
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>stratified_plume_model &#8212; Texas A&amp;M Oil spill / Outfall Calculator 2.1.0 documentation</title>
    <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <h1>Source code for stratified_plume_model</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Stratified Plume Model</span>
<span class="sd">======================</span>

<span class="sd">Simulate a buoyant plume in stratification dominate or quiescent conditions</span>

<span class="sd">This module defines the classes, methods, and functions necessary to simulate</span>
<span class="sd">the buoyant plume behavior in stratification dominant conditions, where the</span>
<span class="sd">effects of crossflows are negligible. The ambient water properties are</span>
<span class="sd">provided through an `ambient.Profile` class object, which contains a</span>
<span class="sd">netCDF4-classic dataset of CTD data and the needed interpolation methods. The</span>
<span class="sd">`dbm` class objects `dbm.FluidParticle` and `dbm.InsolubleParticle` report the</span>
<span class="sd">properties of the dispersed phase during the simulation, and these methods</span>
<span class="sd">are provided to the model through the objects defined in `dispersed_phases`.</span>

<span class="sd">Notes</span>
<span class="sd">-----</span>
<span class="sd">This model is a double plume integral model following the approach in</span>
<span class="sd">Socolofsky et al. (2008), but including the capability to have an arbitrary</span>
<span class="sd">number of dispersed phases, each with its own particle size distribution.</span>

<span class="sd">Detrainment to for subsurface intrusions follows the approach in Crounse</span>
<span class="sd">(2000).</span>

<span class="sd">See Also</span>
<span class="sd">--------</span>
<span class="sd">`single_bubble_model` : Tracks the trajectory of a single bubble, drop or</span>
<span class="sd">    particle through the water column.  The numerical solution used here,</span>
<span class="sd">    including the various object types and their functionality, follows the</span>
<span class="sd">    pattern in the `single_bubble_model`.  The main difference is the more</span>
<span class="sd">    complex state space and governing equations.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="c1"># S. Socolofsky, November 2014, Texas A&amp;M University &lt;socolofs@tamu.edu&gt;.</span>

<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="p">(</span><span class="n">absolute_import</span><span class="p">,</span> <span class="n">division</span><span class="p">,</span> <span class="n">print_function</span><span class="p">)</span>

<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">model_share</span>
<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">seawater</span>
<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">ambient</span>
<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">dbm</span>
<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">dispersed_phases</span>
<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">single_bubble_model</span>
<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">smp</span>

<span class="kn">from</span> <span class="nn">netCDF4</span> <span class="kn">import</span> <span class="n">Dataset</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>

<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="c1"># import matplotlib as mpl</span>
<span class="c1"># import matplotlib.pyplot as plt</span>
<span class="kn">from</span> <span class="nn">scipy.interpolate</span> <span class="kn">import</span> <span class="n">interp1d</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">copy</span>
<span class="kn">from</span> <span class="nn">warnings</span> <span class="kn">import</span> <span class="n">warn</span>
<span class="kn">import</span> <span class="nn">os</span>

<div class="viewcode-block" id="Model"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.Model.html#stratified_plume_model.Model">[docs]</a><span class="k">class</span> <span class="nc">Model</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Master class object for controlling and post-processing the simulation</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    profile : `ambient.Profile` object, default = None</span>
<span class="sd">        An object containing the ambient CTD data and associated methods.</span>
<span class="sd">        The netCDF dataset stored in the `ambient.Profile` object may be open</span>
<span class="sd">        or closed at instantiation.  If open, the initializer will close the</span>
<span class="sd">        file since this model does not support changing the ambient data once</span>
<span class="sd">        initialized.</span>
<span class="sd">    simfile: str, default = None</span>
<span class="sd">        File name of a netCDF file containing the results of a previous</span>
<span class="sd">        simulation run.</span>

<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    profile : `ambient.Profile`</span>
<span class="sd">        Ambient CTD data</span>
<span class="sd">    got_profile : bool</span>
<span class="sd">        Flag indicating whether or not the profile object was successfully</span>
<span class="sd">        loaded into the `Model` object memory.\</span>
<span class="sd">    p : `ModelParams`</span>
<span class="sd">        Container for the fixed model parameters</span>
<span class="sd">    sim_stored : bool</span>
<span class="sd">        Flag indicating whether or not a simulation result is stored in the</span>
<span class="sd">        object memory</span>
<span class="sd">    particles : list</span>
<span class="sd">        List of `dispersed_phases.PlumeParticle` objects describing each</span>
<span class="sd">        dispersed phase in the simulation</span>
<span class="sd">    K_T0 : ndarray</span>
<span class="sd">        Array of the initial values of K_T for each of the dispersed phase</span>
<span class="sd">        particles.  Since this solution is iterative, heat transfer needs</span>
<span class="sd">        to be re-initialized at the start of each iteration, and thus, it is</span>
<span class="sd">        not sufficient to rely on the value of K_T stored inside the</span>
<span class="sd">        `particles` list.</span>
<span class="sd">    R : float</span>
<span class="sd">        Radius of the release point (m)</span>
<span class="sd">    maxit : float</span>
<span class="sd">        Maximum number of iterations allowed in the interative solution</span>
<span class="sd">    toler : float</span>
<span class="sd">        Relative error sufficient to consider the iterative solution to have</span>
<span class="sd">        converged</span>
<span class="sd">    delta_z : float</span>
<span class="sd">        Maximum step size to take in the storage of the simulation solution</span>
<span class="sd">        (m)</span>
<span class="sd">    chem_names : list</span>
<span class="sd">        List of chemical parameters to track for the dissolution</span>
<span class="sd">    zi : ndarray</span>
<span class="sd">        Array of depths for the inner plume solution (m)</span>
<span class="sd">    yi : ndarray</span>
<span class="sd">        Array of state space values computed for the inner plume solution</span>
<span class="sd">    zo : ndarray</span>
<span class="sd">        Array of depths for the outer plume solution (m)</span>
<span class="sd">    yo : ndarray</span>
<span class="sd">        Array of state space values computed for the outer plume solution</span>
<span class="sd">    yi_local : `InnerPlume` object</span>
<span class="sd">        Object that translates the `yi` state space into the comprehensive</span>
<span class="sd">        list of derived variables.</span>
<span class="sd">    yo_local : `OuterPlume` object</span>
<span class="sd">        Object that translates the `yo` state space into the comprehensive</span>
<span class="sd">        list of derived variables.</span>

<span class="sd">    See Also</span>
<span class="sd">    --------</span>
<span class="sd">    simulate, save_sim, load_sim, plot_state_space, plot_all_variables</span>

<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Model.__init__"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.Model.html#stratified_plume_model.Model.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">profile</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">simfile</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">Model</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">profile</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># Create a Model object from a save file</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">load_sim</span><span class="p">(</span><span class="n">simfile</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Create a new Model object</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">profile</span> <span class="o">=</span> <span class="n">profile</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">got_profile</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="n">profile</span><span class="o">.</span><span class="n">close_nc</span><span class="p">()</span>

            <span class="c1"># Get the model parameters that the user cannot adjust</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">ModelParams</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">)</span>

            <span class="c1"># Indicate that a simulation has not yet been conducted</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sim_stored</span> <span class="o">=</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="Model.simulate"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.Model.simulate.html#stratified_plume_model.Model.simulate">[docs]</a>    <span class="k">def</span> <span class="nf">simulate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">R</span><span class="p">,</span> <span class="n">maxit</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">toler</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">delta_z</span><span class="o">=</span><span class="mf">1.</span><span class="p">,</span>
                 <span class="n">plots</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Simulate the plume dynamics from given initial conditions</span>

<span class="sd">        Simulate the buoyant plume using a double plume integral model</span>
<span class="sd">        approach until the plume reaches the surface or the plume momentum</span>
<span class="sd">        goes to zero following complete dissolution of the dispersed</span>
<span class="sd">        phases.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        particles : list of `dispersed_phases.PlumeParticle` objects</span>
<span class="sd">            List of `dispersed_phases.PlumeParticle` objects containing the</span>
<span class="sd">            dispersed phase initial conditions</span>
<span class="sd">        z : float</span>
<span class="sd">            Depth of the release port (m)</span>
<span class="sd">        R : float</span>
<span class="sd">            Radius of the release port (m)</span>
<span class="sd">        maxit : float, default = 10</span>
<span class="sd">            Maximum number of iterations to converge between inner and outer</span>
<span class="sd">            plumes</span>
<span class="sd">        toler : float, default = 0.1</span>
<span class="sd">            Relative error tolerance to accept for convergence (--)</span>
<span class="sd">        delta_z : float, default = 1</span>
<span class="sd">            Maximum step size to use in the simulation (m).  The ODE solver</span>
<span class="sd">            in `calculate` is set up with adaptive step size integration, so</span>
<span class="sd">            in theory this value determines the largest step size in the</span>
<span class="sd">            output data, but not the numerical stability of the calculation.</span>
<span class="sd">        plots : bool, default = True</span>
<span class="sd">            Flag specifying whether or not to generate the state space plots</span>
<span class="sd">            for each iteration of the simulation.  Turn off when running</span>
<span class="sd">            multiple runs from scripts or when not using ``IPython`` with</span>
<span class="sd">            the ``--pylab`` flag.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Store the input parameters</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particles</span> <span class="o">=</span> <span class="n">particles</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">K_T0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">K_T</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span>
                              <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">))])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">R</span> <span class="o">=</span> <span class="n">R</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">maxit</span> <span class="o">=</span> <span class="n">maxit</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">toler</span> <span class="o">=</span> <span class="n">toler</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">delta_z</span> <span class="o">=</span> <span class="n">delta_z</span>

        <span class="c1"># Get the initial conditions for the simulation run</span>
        <span class="n">z0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span> <span class="o">=</span> <span class="n">smp</span><span class="o">.</span><span class="n">main_ic</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span>
                                              <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">R</span><span class="p">)</span>

        <span class="c1"># Store the initial conditions in the inner plume object</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span> <span class="o">=</span> <span class="n">InnerPlume</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span>
                                   <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span> <span class="o">=</span> <span class="n">OuterPlume</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">4</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="o">.</span><span class="n">nchems</span><span class="p">),</span>
                                   <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span><span class="p">,</span>
                                   <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>

        <span class="c1"># Set up the iteration and convergence error</span>
        <span class="nb">iter</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">ea</span> <span class="o">=</span> <span class="mf">9999.</span>

        <span class="c1"># Initialize the neighbor interpolation object to carry solution</span>
        <span class="c1"># from one iteration to the next</span>
        <span class="n">neighbor</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="o">.</span><span class="n">z_max</span><span class="p">]),</span>
                   <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span><span class="o">.</span><span class="n">nchems</span><span class="p">))</span><span class="o">.</span><span class="n">transpose</span><span class="p">())</span>

        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">-- TEXAS A&amp;M OIL-SPILL CALCULATOR (TAMOC) --&#39;</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;-- Stratified Plume Model                 --</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">while</span> <span class="nb">iter</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">maxit</span> <span class="ow">and</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">ea</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">toler</span><span class="p">:</span>

            <span class="c1"># Store old solutions to check for convergence</span>
            <span class="nb">iter</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="nb">iter</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">zi_old</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">)</span>
                <span class="n">zo_old</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zo</span><span class="p">)</span>
                <span class="n">yi_old</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">yi</span><span class="p">)</span>
                <span class="n">yo_old</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">yo</span><span class="p">)</span>

            <span class="c1"># Enter the main calculation loop</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">Iteration </span><span class="si">%2.2d</span><span class="s1">---------------------------------------&#39;</span>
                  <span class="o">%</span> <span class="nb">iter</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">  Calculate inner plume...&#39;</span><span class="p">)</span>
            <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi</span><span class="p">,</span> <span class="n">neighbor</span> <span class="o">=</span> <span class="n">inner_main</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">delta_z</span><span class="p">)</span>

            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">  Calculate outer plume...&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">zo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yo</span><span class="p">,</span> <span class="n">neighbor</span> <span class="o">=</span> <span class="n">outer_main</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">delta_z</span><span class="p">)</span>

            <span class="c1"># Check the convergence criteria</span>
            <span class="k">if</span> <span class="nb">iter</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="c1"># Compare the latest two solutions of the state space</span>
                <span class="n">ea</span>  <span class="o">=</span> <span class="n">err_check</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">zo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yo</span><span class="p">,</span> <span class="n">zi_old</span><span class="p">,</span>
                                <span class="n">yi_old</span><span class="p">,</span> <span class="n">zo_old</span><span class="p">,</span> <span class="n">yo_old</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="p">,</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">)</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">  Relative error:  </span><span class="si">%g</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">ea</span><span class="p">)</span>

            <span class="c1"># Plot the state space to help track the convergence</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sim_stored</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">if</span> <span class="n">plots</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">plot_state_space</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

            <span class="c1"># Restart heat transfer</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">)):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">K_T</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">K_T0</span><span class="p">[</span><span class="n">i</span><span class="p">]</span></div>

<div class="viewcode-block" id="Model.save_sim"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.Model.save_sim.html#stratified_plume_model.Model.save_sim">[docs]</a>    <span class="k">def</span> <span class="nf">save_sim</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fname</span><span class="p">,</span> <span class="n">profile_path</span><span class="p">,</span> <span class="n">profile_info</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Save the current simulation results</span>

<span class="sd">        Save the current simulation results and the model parameters so that</span>
<span class="sd">        all information needed to rebuild the class object is stored in a</span>
<span class="sd">        file.  The output data are stored in netCDF4-classic format.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        fname : str</span>
<span class="sd">            File name of the file to write</span>
<span class="sd">        profile_path : str</span>
<span class="sd">            String stating the file path to the ambient profile data relative</span>
<span class="sd">            to the directory where `fname` will be saved.</span>
<span class="sd">        profile_info : str</span>
<span class="sd">            Single line of text describing the ambient profile data.</span>

<span class="sd">        See Also</span>
<span class="sd">        --------</span>
<span class="sd">        dispersed_phases.save_particle_to_nc_file</span>

<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        It does not make sense to store the ambient data together with every</span>
<span class="sd">        simulation output file.  On the other hand, the simulation results</span>
<span class="sd">        may be meaningless without the context of the ambient data.  The</span>
<span class="sd">        parameter `profile_path` provides a means to automatically load the</span>
<span class="sd">        ambient data assuming the profile data are kept in the same place</span>
<span class="sd">        relative to the output file.  Since this cannot be guaranteed, the</span>
<span class="sd">        `profile_info` variable provides additional descriptive information</span>
<span class="sd">        so that the ambient data can be identified if they have been moved.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sim_stored</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;No simulation results to store...&#39;</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Saved nothing to netCDF file.</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">return</span>

        <span class="c1"># Create the netCDF dataset object</span>
        <span class="n">title</span> <span class="o">=</span> <span class="s1">&#39;Simulation results for the TAMOC Stratified Plume Model&#39;</span>
        <span class="n">nc</span> <span class="o">=</span> <span class="n">model_share</span><span class="o">.</span><span class="n">tamoc_nc_file</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">title</span><span class="p">,</span> <span class="n">profile_path</span><span class="p">,</span>
            <span class="n">profile_info</span><span class="p">)</span>

        <span class="c1"># Create variables for the dimensions</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;profile&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="n">nsi</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;nsi&#39;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="o">.</span><span class="n">y0</span><span class="p">))</span>
        <span class="n">nso</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;nso&#39;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span><span class="o">.</span><span class="n">y0</span><span class="p">))</span>
        <span class="n">params</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>

        <span class="c1"># Create variables for the initial conditions and model setup</span>
        <span class="n">R</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,))</span>
        <span class="n">R</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;radius of the release point&#39;</span>
        <span class="n">R</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;R&#39;</span>
        <span class="n">R</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m&#39;</span>

        <span class="n">Ta</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;Ta&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,))</span>
        <span class="n">Ta</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;ambient temperature at the release point&#39;</span>
        <span class="n">Ta</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;Ta&#39;</span>
        <span class="n">Ta</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;K&#39;</span>

        <span class="n">Sa</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;Sa&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,))</span>
        <span class="n">Sa</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;ambient salinity at the release point&#39;</span>
        <span class="n">Sa</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;Sa&#39;</span>
        <span class="n">Sa</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;psu&#39;</span>

        <span class="n">P</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;P&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,))</span>
        <span class="n">P</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;ambient pressure at the release point&#39;</span>
        <span class="n">P</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;P&#39;</span>
        <span class="n">P</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;Pa&#39;</span>

        <span class="n">maxit</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;maxit&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,))</span>
        <span class="n">maxit</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;maximum allowable number of iterations&#39;</span>
        <span class="n">maxit</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;maxit&#39;</span>
        <span class="n">maxit</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>

        <span class="n">toler</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;toler&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,))</span>
        <span class="n">toler</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;relative error tolerance for convergence&#39;</span>
        <span class="n">toler</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;toler&#39;</span>
        <span class="n">toler</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>

        <span class="n">delta_z</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;delta_z&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;params&#39;</span><span class="p">,))</span>
        <span class="n">delta_z</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;maximum step size in output&#39;</span>
        <span class="n">delta_z</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;delta_z&#39;</span>
        <span class="n">delta_z</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m&#39;</span>

        <span class="c1"># Create the independent variables (depth for inner and outer plumes)</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="s1">&#39;profile&#39;</span><span class="p">,))</span>
        <span class="n">z</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;depth below the water surface&#39;</span>
        <span class="n">z</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;depth&#39;</span>
        <span class="n">z</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m&#39;</span>
        <span class="n">z</span><span class="o">.</span><span class="n">axis</span> <span class="o">=</span> <span class="s1">&#39;Z&#39;</span>
        <span class="n">z</span><span class="o">.</span><span class="n">positive</span> <span class="o">=</span> <span class="s1">&#39;down&#39;</span>

        <span class="c1"># Create the dependent variables (inner and outer plumes)</span>
        <span class="n">yi</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;yi&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="s1">&#39;nsi&#39;</span><span class="p">,))</span>
        <span class="n">yi</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;inner plume state space&#39;</span>
        <span class="n">yi</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;yi&#39;</span>
        <span class="n">yi</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;variable&#39;</span>
        <span class="n">yi</span><span class="o">.</span><span class="n">coordinate</span> <span class="o">=</span> <span class="s1">&#39;z&#39;</span>

        <span class="n">yo</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;yo&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="s1">&#39;nso&#39;</span><span class="p">,))</span>
        <span class="n">yo</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;outer plume state space&#39;</span>
        <span class="n">yo</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;yo&#39;</span>
        <span class="n">yo</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;variable&#39;</span>
        <span class="n">yo</span><span class="o">.</span><span class="n">coordinate</span> <span class="o">=</span> <span class="s1">&#39;z&#39;</span>

        <span class="c1"># Store the initial conditions</span>
        <span class="n">R</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">R</span>
        <span class="n">Ta</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">Sa</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">P</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">),</span>
            <span class="p">[</span><span class="s1">&#39;temperature&#39;</span><span class="p">,</span> <span class="s1">&#39;salinity&#39;</span><span class="p">,</span> <span class="s1">&#39;pressure&#39;</span><span class="p">])</span>
        <span class="n">maxit</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">maxit</span>
        <span class="n">toler</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">toler</span>
        <span class="n">delta_z</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">delta_z</span>

        <span class="c1"># Store all of the dispersed phase particles</span>
        <span class="n">dispersed_phases</span><span class="o">.</span><span class="n">save_particle_to_nc_file</span><span class="p">(</span><span class="n">nc</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">K_T0</span><span class="p">)</span>

        <span class="c1"># Save the dependent variable solution</span>
        <span class="n">z</span><span class="o">.</span><span class="n">n_inner</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">)</span>
        <span class="n">z</span><span class="o">.</span><span class="n">n_outer</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zo</span><span class="p">)</span>
        <span class="n">z</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">[:]</span>
        <span class="n">z</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">zo</span><span class="p">[:]</span>

        <span class="c1"># Save the state space solutions for the inner and outer plumes</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s1">&#39;nsi&#39;</span><span class="p">])):</span>
            <span class="n">yi</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">),</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s1">&#39;nso&#39;</span><span class="p">])):</span>
            <span class="n">yo</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zo</span><span class="p">),</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">yo</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span>

        <span class="c1"># Close the netCDF dataset</span>
        <span class="n">nc</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

<div class="viewcode-block" id="Model.save_txt"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.Model.save_txt.html#stratified_plume_model.Model.save_txt">[docs]</a>    <span class="k">def</span> <span class="nf">save_txt</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">base_name</span><span class="p">,</span> <span class="n">profile_path</span><span class="p">,</span> <span class="n">profile_info</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Save the state space in ascii text format for exporting</span>

<span class="sd">        Save the state space (dependent and independent variables) in an</span>
<span class="sd">        ascii text file for exporting to other programs (e.g., Matlab).</span>
<span class="sd">        Because the vertical coordinate is different for the inner and</span>
<span class="sd">        outer plume solutions and because we want this data to be easily</span>
<span class="sd">        loadable in Matlab (i.e., each column of data must have the same</span>
<span class="sd">        number of rows), this method writes two data files, one for the</span>
<span class="sd">        inner plume and one for the outer plume.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        base_name : str</span>
<span class="sd">            Base file name for the output file.  This method appends &#39;inner&#39;</span>
<span class="sd">            and &#39;outer&#39; to the inner and outer solutions upstream of the</span>
<span class="sd">            dot-extension.</span>
<span class="sd">        profile_path : str</span>
<span class="sd">            String stating the file path to the ambient profile data relative</span>
<span class="sd">            to the directory where `fname` will be saved.</span>
<span class="sd">        profile_info : str</span>
<span class="sd">            Single line of text describing the ambient profile data.</span>

<span class="sd">        See Also</span>
<span class="sd">        --------</span>
<span class="sd">        bent_plume_model.Model.save_txt, single_bubble_model.Model.save_txt</span>

<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        The output will be organized in columns, with each column as follows:</span>

<span class="sd">            0 : depth (m)</span>
<span class="sd">            1-n : state space</span>

<span class="sd">        A header will be written to a separate file with `yi_header` and</span>
<span class="sd">        `yo_header` appended to the base file name given above specifying</span>
<span class="sd">        the exact contents of the state space.</span>

<span class="sd">        These output files are written using the `numpy.savetxt` method.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sim_stored</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;No simulation results to store...&#39;</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Saved nothing to text file.</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">return</span>

        <span class="c1"># Create the header string that contains the column descriptions</span>
        <span class="c1"># for the inner plume</span>
        <span class="n">p_list</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Stratified Plume Model ASCII Output File </span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">]</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Created: &#39;</span> <span class="o">+</span> <span class="n">datetime</span><span class="o">.</span><span class="n">today</span><span class="p">()</span><span class="o">.</span><span class="n">isoformat</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Simulation based on CTD data in:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">profile_path</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">profile_info</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Column Descriptions:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    0:  Depth in m</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    1:  Volume flux Q in m^3/s</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    2:  Momentum flux M in m^4/s^2</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    3:  Salinity flux S in psu m^3/s</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    4:  Heat flux H in J/s</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">idx</span> <span class="o">=</span> <span class="mi">4</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="o">.</span><span class="n">np</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">composition</span><span class="p">)):</span>
                <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="s1">&#39;    </span><span class="si">%d</span><span class="s1">:  Total mass flux of </span><span class="si">%s</span><span class="s1"> in particle </span><span class="si">%d</span><span class="s1"> in kg/s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span>
                    <span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">composition</span><span class="p">[</span><span class="n">j</span><span class="p">],</span> <span class="n">i</span><span class="p">))</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">%d</span><span class="s1">:  Total heat flux of particle </span><span class="si">%d</span><span class="s1"> in J/s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span>
                <span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">%d</span><span class="s1">:  Age of particle </span><span class="si">%d</span><span class="s1"> in s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">%d</span><span class="s1">:  x-position of particle </span><span class="si">%d</span><span class="s1"> in m</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span>
                <span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">%d</span><span class="s1">:  y-position of particle </span><span class="si">%d</span><span class="s1"> in m</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span>
                <span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">%d</span><span class="s1">:  depth of particle </span><span class="si">%d</span><span class="s1"> in m</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span>
                <span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="o">.</span><span class="n">nchems</span><span class="p">):</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">%d</span><span class="s1">:  Dissolved mass flux of </span><span class="si">%s</span><span class="s1"> in kg/s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span>
                          <span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="o">.</span><span class="n">chem_names</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
        <span class="n">header_inner</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">p_list</span><span class="p">)</span>

        <span class="c1"># Create the header string that contains the column descriptions</span>
        <span class="c1"># for the outer plume</span>
        <span class="n">p_list</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Stratified Plume Model ASCII Output File </span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">]</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Created: &#39;</span> <span class="o">+</span> <span class="n">datetime</span><span class="o">.</span><span class="n">today</span><span class="p">()</span><span class="o">.</span><span class="n">isoformat</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Simulation based on CTD data in:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">profile_path</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">profile_info</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;Column Descriptions:</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    0:  Depth in m</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    1:  Volume flux Q in m^3/s</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    2:  Momentum flux M in m^4/s^2</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    3:  Salinity flux S in psu m^3/s</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    4:  Heat flux H in J/s</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="n">idx</span> <span class="o">=</span> <span class="mi">4</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span><span class="o">.</span><span class="n">nchems</span><span class="p">):</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">p_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;    </span><span class="si">%d</span><span class="s1">:  Dissolved mass flux of </span><span class="si">%s</span><span class="s1"> in kg/s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span>
                          <span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="o">.</span><span class="n">chem_names</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
        <span class="n">header_outer</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">p_list</span><span class="p">)</span>

        <span class="c1"># Assemble and write the inner plume data</span>
        <span class="n">data_inner</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">atleast_2d</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">)</span><span class="o">.</span><span class="n">transpose</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi</span><span class="p">))</span>
        <span class="n">np</span><span class="o">.</span><span class="n">savetxt</span><span class="p">(</span><span class="n">base_name</span> <span class="o">+</span> <span class="s1">&#39;_inner.txt&#39;</span><span class="p">,</span> <span class="n">data_inner</span><span class="p">)</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">base_name</span> <span class="o">+</span> <span class="s1">&#39;_inner_header.txt&#39;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">dat_file</span><span class="p">:</span>
            <span class="n">dat_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">header_inner</span><span class="p">)</span>

        <span class="c1"># Assemble and write the outer plume data</span>
        <span class="n">data_outer</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">atleast_2d</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zo</span><span class="p">)</span><span class="o">.</span><span class="n">transpose</span><span class="p">(),</span> <span class="bp">self</span><span class="o">.</span><span class="n">yo</span><span class="p">))</span>
        <span class="n">np</span><span class="o">.</span><span class="n">savetxt</span><span class="p">(</span><span class="n">base_name</span> <span class="o">+</span> <span class="s1">&#39;_outer.txt&#39;</span><span class="p">,</span> <span class="n">data_outer</span><span class="p">)</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">base_name</span> <span class="o">+</span> <span class="s1">&#39;_outer_header.txt&#39;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">dat_file</span><span class="p">:</span>
            <span class="n">dat_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">header_outer</span><span class="p">)</span></div>

<div class="viewcode-block" id="Model.load_sim"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.Model.load_sim.html#stratified_plume_model.Model.load_sim">[docs]</a>    <span class="k">def</span> <span class="nf">load_sim</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fname</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Load in a saved simulation result file for post-processing</span>

<span class="sd">        Load in a saved simulation result file and rebuild the `Model`</span>
<span class="sd">        object attributes.  The input files are in netCDF4-classic data</span>
<span class="sd">        format.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        fname : str</span>
<span class="sd">            File name of the file to read</span>

<span class="sd">        See Also</span>
<span class="sd">        --------</span>
<span class="sd">        save_sim</span>

<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        This method will attempt to load the ambient profile data from the</span>
<span class="sd">        `profile_path` attribute of the `fname` netCDF file.  If the load</span>
<span class="sd">        fails, a warning will be reported to the terminal, but the other</span>
<span class="sd">        steps of loading the `Model` object attributes will be performed.</span>

<span class="sd">        This method performs the same function as the</span>
<span class="sd">        `single_bubble_model.Model.load_sim` method, but with slightly</span>
<span class="sd">        different variables and variable dimensions.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Open the netCDF dataset object containing the simulation results</span>
        <span class="n">nc</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="n">fname</span><span class="p">)</span>

        <span class="c1"># Try to get the profile data</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">profile</span> <span class="o">=</span> <span class="n">model_share</span><span class="o">.</span><span class="n">profile_from_model_savefile</span><span class="p">(</span><span class="n">nc</span><span class="p">,</span> <span class="n">fname</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">ModelParams</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">got_profile</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">got_profile</span> <span class="o">=</span> <span class="kc">False</span>

        <span class="c1"># Create the dispersed_phases.PlumeParticle objects</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span> <span class="o">=</span> \
            <span class="n">dispersed_phases</span><span class="o">.</span><span class="n">load_particle_from_nc_file</span><span class="p">(</span><span class="n">nc</span><span class="p">)</span>

        <span class="c1"># Create the remaining model attributes</span>
        <span class="n">nzi</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">n_inner</span>
        <span class="n">nzo</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">n_outer</span>
        <span class="n">nsi</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s1">&#39;nsi&#39;</span><span class="p">])</span>
        <span class="n">nso</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s1">&#39;nso&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">K_T0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">K_T</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span>
                              <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">))])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">R</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;R&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">maxit</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;maxit&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">toler</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;toler&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">delta_z</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;delta_z&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">got_profile</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span> <span class="o">=</span> <span class="n">InnerPlume</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]]),</span>
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;yi&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">,:],</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span> <span class="o">=</span> \
                <span class="n">OuterPlume</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">][</span><span class="n">nzo</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">]]),</span>
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;yo&#39;</span><span class="p">][</span><span class="n">nzo</span><span class="o">-</span><span class="mi">1</span><span class="p">,:],</span> <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">zi</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="n">nzi</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">zo</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="n">nzo</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">yi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nzi</span><span class="p">,</span> <span class="n">nsi</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">yo</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">nzo</span><span class="p">,</span> <span class="n">nso</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nsi</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">yi</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;yi&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="n">nzi</span><span class="p">,</span><span class="n">i</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nso</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">yo</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;yo&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="n">nzo</span><span class="p">,</span><span class="n">i</span><span class="p">]</span>

        <span class="c1"># Close the netCDF dataset</span>
        <span class="n">nc</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sim_stored</span> <span class="o">=</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Model.plot_state_space"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.Model.plot_state_space.html#stratified_plume_model.Model.plot_state_space">[docs]</a>    <span class="k">def</span> <span class="nf">plot_state_space</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fig</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot the simulation state space</span>

<span class="sd">        Plot the standard set of state space variables used to evaluate</span>
<span class="sd">        model convergence and quality of the model solution</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        fig : int</span>
<span class="sd">            Number of the figure window in which to draw the plot</span>

<span class="sd">        See Also</span>
<span class="sd">        --------</span>
<span class="sd">        plot_all_variables</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">import</span> <span class="nn">matplotlib</span> <span class="k">as</span> <span class="nn">mpl</span>
        <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sim_stored</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;No simulation results available to plot...&#39;</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Plotting nothing.</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">return</span>

        <span class="c1"># Plot the results</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Plotting the state space...&#39;</span><span class="p">)</span>
        <span class="n">plot_state_space</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">zo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yo</span><span class="p">,</span>
                         <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span>
                         <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">fig</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Done.</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Model.plot_all_variables"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.Model.plot_all_variables.html#stratified_plume_model.Model.plot_all_variables">[docs]</a>    <span class="k">def</span> <span class="nf">plot_all_variables</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fig</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Plot a comprehensive suite of simulation results</span>

<span class="sd">        Generate a comprehensive suite of graphs showing the state and</span>
<span class="sd">        derived variables along with ambient profile data in order to</span>
<span class="sd">        view the model output for detailed analysis.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        fig : int</span>
<span class="sd">            Number of the figure window in which to draw the plot</span>

<span class="sd">        See Also</span>
<span class="sd">        --------</span>
<span class="sd">        plot_state_space</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">import</span> <span class="nn">matplotlib</span> <span class="k">as</span> <span class="nn">mpl</span>
        <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sim_stored</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;No simulation results available to plot...&#39;</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Plotting nothing.</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
            <span class="k">return</span>

        <span class="c1"># Plot the results</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Plotting the full variable suite...&#39;</span><span class="p">)</span>
        <span class="n">plot_all_variables</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yi</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">zo</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yo</span><span class="p">,</span>
                           <span class="bp">self</span><span class="o">.</span><span class="n">yi_local</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">yo_local</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">particles</span><span class="p">,</span>
                           <span class="bp">self</span><span class="o">.</span><span class="n">profile</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">fig</span><span class="p">)</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Done.</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="ModelParams"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.ModelParams.html#stratified_plume_model.ModelParams">[docs]</a><span class="k">class</span> <span class="nc">ModelParams</span><span class="p">(</span><span class="n">single_bubble_model</span><span class="o">.</span><span class="n">ModelParams</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Fixed model parameters for the stratified plume model</span>

<span class="sd">    This class stores the set of model parameters that should not be adjusted</span>
<span class="sd">    by the user and that are needed by the stratified plume model.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>

<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    rho_r : float</span>
<span class="sd">        Reference density (kg/m^3) evaluated at mid-depth of the water body.</span>
<span class="sd">    alpha_1 : float</span>
<span class="sd">        entrainment coefficient from the ambient fluid to the inner plume</span>
<span class="sd">    alpha_2 : float</span>
<span class="sd">        entrainment coefficient from the inner plume to the outer plume</span>
<span class="sd">    alpha_3 : float</span>
<span class="sd">        entrainment coefficient from the ambient fluid to the outer plume</span>
<span class="sd">    lambda_2 : float</span>
<span class="sd">        spreading rate of dissolved constituents</span>
<span class="sd">    epsilon : float</span>
<span class="sd">        continuous peeling parameter (see Crounse 2000)</span>
<span class="sd">    c1 : float</span>
<span class="sd">        coefficient for counterflow entrainment model</span>
<span class="sd">    c2 : float</span>
<span class="sd">        coefficient for counterflow entrainment model</span>
<span class="sd">    fe : float</span>
<span class="sd">        extra entrainment factor when the inner plume hits the free</span>
<span class="sd">        surface</span>
<span class="sd">    gamma_i : float</span>
<span class="sd">        momentum amplification factor for inner plume (see Milgram 1983)</span>
<span class="sd">    gamma_o : float</span>
<span class="sd">        momentum amplification factor for outer plume</span>
<span class="sd">    Fr_0 : float</span>
<span class="sd">        initial plume Froude number (see Wueest et al. 1992)</span>
<span class="sd">    Fro_0 : float</span>
<span class="sd">        initial plume Froude number for outer plume segments</span>
<span class="sd">    nwidths : float</span>
<span class="sd">        average size of detraining eddies as a fraction of the plume</span>
<span class="sd">        half-width</span>
<span class="sd">    naverage : float</span>
<span class="sd">        number of previous outer plume solutions to average</span>
<span class="sd">    g : float</span>
<span class="sd">        acceleration of gravity (m/s^2)</span>
<span class="sd">    Ru : float</span>
<span class="sd">        universal ideal gas constant (J/(mol K))</span>

<span class="sd">    Notes</span>
<span class="sd">    -----</span>
<span class="sd">    This object inherits the `single_bubble_model.ModelParams` object, which</span>
<span class="sd">    defines the attribute `rho_r`.</span>

<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="ModelParams.__init__"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.ModelParams.html#stratified_plume_model.ModelParams.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">profile</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">ModelParams</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">profile</span><span class="p">)</span>

        <span class="c1"># Set the model parameters to the values recommended by Socolofsky</span>
        <span class="c1"># et al. (2008)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">alpha_j</span> <span class="o">=</span> <span class="mf">0.055</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">alpha_Fr</span> <span class="o">=</span> <span class="mf">0.544</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">alpha_1</span> <span class="o">=</span> <span class="mf">0.055</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">alpha_2</span> <span class="o">=</span> <span class="mf">0.110</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">alpha_3</span> <span class="o">=</span> <span class="mf">0.110</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lambda_2</span> <span class="o">=</span> <span class="mf">1.00</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">epsilon</span> <span class="o">=</span> <span class="mf">0.015</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">qdis_ic</span> <span class="o">=</span> <span class="mf">0.1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">c1</span> <span class="o">=</span> <span class="mf">0.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">c2</span> <span class="o">=</span> <span class="mf">1.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fe</span> <span class="o">=</span> <span class="mf">0.1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gamma_i</span> <span class="o">=</span> <span class="mf">1.10</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">gamma_o</span> <span class="o">=</span> <span class="mf">1.10</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">Fr_0</span> <span class="o">=</span> <span class="mf">1.6</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">Fro_0</span> <span class="o">=</span> <span class="mf">0.1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nwidths</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">naverage</span> <span class="o">=</span> <span class="mi">1</span></div></div>


<div class="viewcode-block" id="InnerPlume"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.InnerPlume.html#stratified_plume_model.InnerPlume">[docs]</a><span class="k">class</span> <span class="nc">InnerPlume</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Manages the inner plume state space and derived variables</span>

<span class="sd">    Manages storage and calculation of the derived variables for the inner</span>
<span class="sd">    plume as a function of the state space.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    z0 : float</span>
<span class="sd">        Starting depth (m) of the inner plume</span>
<span class="sd">    y0 : ndarray</span>
<span class="sd">        Initial conditions for the inner plume.</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>
<span class="sd">    particles : list of `dispersed_phases.PlumeParticle` objects</span>
<span class="sd">        List of `dispersed_phases.PlumeParticle` objects containing the</span>
<span class="sd">        dispersed phase local conditions and behavior.</span>
<span class="sd">    p : `ModelParams` object</span>
<span class="sd">        Object containing the fixed model parameters for the stratified</span>
<span class="sd">        plume model.</span>
<span class="sd">    chem_names : str list</span>
<span class="sd">        List of chemical names to track for the dissolution.</span>

<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    z0 : float</span>
<span class="sd">        Starting depth (m) of the inner plume</span>
<span class="sd">    y0 : ndarray</span>
<span class="sd">        Initial conditions for the inner plume</span>
<span class="sd">    chem_names : str lit</span>
<span class="sd">        List of chemical names to track for the dissolution</span>
<span class="sd">    len : int</span>
<span class="sd">        Number of variables in the state space vector y</span>
<span class="sd">    nchems : int</span>
<span class="sd">        Number of chemical names to track for the dissolution</span>
<span class="sd">    np : int</span>
<span class="sd">        Number of dispersed phase particle objects</span>
<span class="sd">    z : float</span>
<span class="sd">        Current value of the depth (m)</span>
<span class="sd">    y : ndarray</span>
<span class="sd">        Current value of the state space vector</span>
<span class="sd">    Q : float</span>
<span class="sd">        Continuous phase volume flux (m^3/s)</span>
<span class="sd">    J : float</span>
<span class="sd">        Continuous phase kinematic momentum flux (m^4/s^2)</span>
<span class="sd">    S : float</span>
<span class="sd">        Plume salinity flux (psu m^3/s)</span>
<span class="sd">    H : float</span>
<span class="sd">        Continuous phase heat flux (J/s)</span>
<span class="sd">    M_p : dict of ndarrays</span>
<span class="sd">        For integer key: the total mass fluxes (kg/s) of each component in a</span>
<span class="sd">        particle.</span>
<span class="sd">    H_p : ndarray</span>
<span class="sd">        Total heat flux for each particle (J/s)</span>
<span class="sd">    C : ndarray</span>
<span class="sd">        Mass flux of dissolved components (kg/s)</span>
<span class="sd">    Ta : float</span>
<span class="sd">        Ambient temperature outside the plume (K)</span>
<span class="sd">    Sa : float</span>
<span class="sd">        Ambient salinity outside the plume (psu)</span>
<span class="sd">    P : float</span>
<span class="sd">        Local pressure (Pa)</span>
<span class="sd">    rho_a : float</span>
<span class="sd">        Ambient density outside the plume (kg/m^3)</span>
<span class="sd">    ca : ndarray</span>
<span class="sd">        Ambient concentrations outside the plume (kg/m^3)</span>
<span class="sd">    u : float</span>
<span class="sd">        Velocity of the continuous phase fluid (m/s)</span>
<span class="sd">    b : float</span>
<span class="sd">        Plume half-width (m)</span>
<span class="sd">    s : float</span>
<span class="sd">        Salinity of the plume fluid (psu)</span>
<span class="sd">    T : float</span>
<span class="sd">        Temperature of the plume fluid (K)</span>
<span class="sd">    c : ndarray</span>
<span class="sd">        Concentrations of the dissolved components in the plume fluid</span>
<span class="sd">        (kg/m^3)</span>
<span class="sd">    rho : float</span>
<span class="sd">        Density of the continuous phase inside the plume (kg/m^3)</span>
<span class="sd">    xi : ndarray</span>
<span class="sd">        Void fraction of each particle object (--)</span>
<span class="sd">    fb : ndarray</span>
<span class="sd">        Buoyant force of each particle object (kg/m^3)</span>
<span class="sd">    Xi : float</span>
<span class="sd">        Total void fraction in the plume (--)</span>
<span class="sd">    Fb : float</span>
<span class="sd">        Total buoyant force of all particles in the plume (??)</span>
<span class="sd">    Ep : float</span>
<span class="sd">        Local peeling flux (m^2/s)</span>

<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="InnerPlume.__init__"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.InnerPlume.html#stratified_plume_model.InnerPlume.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">chem_names</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">InnerPlume</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="c1"># Store the input variables that will stay with the inner plume</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">z0</span> <span class="o">=</span> <span class="n">z0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">y0</span> <span class="o">=</span> <span class="n">y0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span> <span class="o">=</span> <span class="n">chem_names</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">len</span> <span class="o">=</span> <span class="n">y0</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nchems</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">chem_names</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">np</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">)</span>

        <span class="c1"># Extract the state variables and compute the derived quantities</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span></div>

<div class="viewcode-block" id="InnerPlume.update"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.InnerPlume.update.html#stratified_plume_model.InnerPlume.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Update the `InnerPlume` object with the current local conditions</span>

<span class="sd">        Extract the state variables and compute the derived quantities given</span>
<span class="sd">        the current local conditions.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        z : float</span>
<span class="sd">            Local depth (m)</span>
<span class="sd">        y : ndarray</span>
<span class="sd">            Local values of the inner plume state space</span>
<span class="sd">        particles : list of `dispersed_phases.PlumeParticle` objects</span>
<span class="sd">            List of `dispersed_phaes.PlumeParticle` objects containing the</span>
<span class="sd">            dispersed phase local conditions and behavior.</span>
<span class="sd">        profile : `ambient.Profile` object</span>
<span class="sd">            The ambient CTD object used by the simulation.</span>
<span class="sd">        p : `ModelParams` object</span>
<span class="sd">            Object containing the fixed model parameters for the stratified</span>
<span class="sd">            plume model.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Save the current state space</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="n">z</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">y</span>

        <span class="c1"># Extract the state space variables from y</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">Q</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">J</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">S</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">H</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
        <span class="n">idx</span> <span class="o">=</span> <span class="mi">4</span>
        <span class="n">M_p</span> <span class="o">=</span> <span class="p">{}</span> <span class="c1"># Since inert particles have different components than soluble</span>
        <span class="n">H_p</span> <span class="o">=</span> <span class="p">[]</span> <span class="c1"># Each particle has one value for temperature (heat)</span>
        <span class="n">t_p</span> <span class="o">=</span> <span class="p">[]</span> <span class="c1"># Each particle has its own age (time since release)</span>
        <span class="n">x_p</span> <span class="o">=</span> <span class="p">[]</span> <span class="c1"># Each paticle will have three components of position</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">np</span><span class="p">):</span>
            <span class="n">M_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="n">idx</span><span class="p">:</span><span class="n">idx</span> <span class="o">+</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">nc</span><span class="p">]</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">nc</span>
            <span class="n">H_p</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">idx</span><span class="p">:</span><span class="n">idx</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">t_p</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">idx</span><span class="p">:</span><span class="n">idx</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">x_p</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">idx</span><span class="p">:</span><span class="n">idx</span> <span class="o">+</span> <span class="mi">3</span><span class="p">])</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">3</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">M_p</span> <span class="o">=</span> <span class="n">M_p</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">H_p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">H_p</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">t_p</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x_p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">x_p</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">nchems</span> <span class="o">&gt;=</span> <span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">C</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="n">idx</span><span class="p">:]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">C</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([])</span>

        <span class="c1"># Get the local ambient conditions</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">Ta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Sa</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">P</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;temperature&#39;</span><span class="p">,</span>
                                   <span class="s1">&#39;salinity&#39;</span><span class="p">,</span> <span class="s1">&#39;pressure&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">rho_a</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Ta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Sa</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">P</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ca</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span> <span class="o">&gt;</span> <span class="mf">0.</span><span class="p">:</span>
            <span class="c1"># Compute the continuous phase derived quantities</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">u</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">J</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">J</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">S</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">T</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">H</span> <span class="o">/</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">rho_r</span> <span class="o">*</span> <span class="n">seawater</span><span class="o">.</span><span class="n">cp</span><span class="p">()</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">C</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rho</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">s</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">P</span><span class="p">)</span>

            <span class="c1"># Compute the dispersed phase derived quantities</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">xi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">np</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fb</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">np</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">np</span><span class="p">):</span>
                <span class="c1"># Update the particle properties</span>
                <span class="n">m_p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">M_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">/</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">nb0</span>
                <span class="n">T_p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">H_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">M_p</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">*</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">cp</span><span class="p">)</span>
                <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">m_p</span><span class="p">,</span> <span class="n">T_p</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">P</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">s</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">T</span><span class="p">,</span>
                                    <span class="bp">self</span><span class="o">.</span><span class="n">t_p</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

                <span class="c1"># Calculate the individual void fractions in the plume</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">xi</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">M_p</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">/</span> <span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">rho_p</span> <span class="o">*</span>
                    <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">lambda_1</span><span class="o">**</span><span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="o">**</span><span class="mi">2</span> <span class="o">*</span>
                    <span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">us</span> <span class="o">+</span> <span class="mf">2.</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">u</span> <span class="o">/</span> <span class="p">(</span><span class="mf">1.</span> <span class="o">+</span>
                    <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">lambda_1</span><span class="o">**</span><span class="mi">2</span><span class="p">))))</span>

                <span class="c1"># Calculate the buoyant force of the current particle</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">fb</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">lambda_1</span><span class="o">**</span><span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">xi</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> \
                             <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">rho_a</span> <span class="o">-</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">rho_p</span><span class="p">)</span>

                <span class="c1"># Force void fraction and bubble force to zero if bubbles</span>
                <span class="c1"># have dissolved</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">rho</span> <span class="o">==</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">rho_p</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">xi</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">fb</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.</span>

            <span class="c1"># Compute the net void fraction and buoyancy flux</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">Xi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xi</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">Fb</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fb</span><span class="p">)</span>

            <span class="c1"># Get the peeling flux</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">Ep</span> <span class="o">=</span> <span class="n">smp</span><span class="o">.</span><span class="n">cp_model</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">epsilon</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">rho_a</span><span class="p">,</span>
                                    <span class="bp">self</span><span class="o">.</span><span class="n">rho</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">g</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">rho_r</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">u</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># There is no inner plume or the momentum is reversing</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">u</span> <span class="o">=</span> <span class="mf">0.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="mf">0.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Sa</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">T</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Ta</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ca</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rho</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Ta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Sa</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">P</span><span class="p">)</span>

            <span class="c1"># Compute the dispersed phase derived quantities</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">xi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">np</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fb</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">np</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">np</span><span class="p">):</span>
                <span class="c1"># Update the particle properties</span>
                <span class="n">m_p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">M_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.</span>
                <span class="n">T_p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Ta</span>
                <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">m_p</span><span class="p">,</span> <span class="n">T_p</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">P</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Sa</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Ta</span><span class="p">,</span>
                                    <span class="bp">self</span><span class="o">.</span><span class="n">t_p</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

            <span class="c1"># Compute the net void fraction and buoyancy flux</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">Xi</span> <span class="o">=</span> <span class="mf">0.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">Fb</span> <span class="o">=</span> <span class="mf">0.</span>

            <span class="c1"># Get the peeling flux</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">Ep</span> <span class="o">=</span> <span class="mf">0.</span>

        <span class="c1"># Get the shear entrainment coefficient</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">alpha_s</span> <span class="o">=</span> <span class="n">dispersed_phases</span><span class="o">.</span><span class="n">shear_entrainment</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">u</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span>
                       <span class="bp">self</span><span class="o">.</span><span class="n">rho</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">rho_a</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">b</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span></div></div>

<div class="viewcode-block" id="OuterPlume"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.OuterPlume.html#stratified_plume_model.OuterPlume">[docs]</a><span class="k">class</span> <span class="nc">OuterPlume</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Manages the outer plume state space and derived variables</span>

<span class="sd">    Manages storage and calculation of the derived variables for the outer</span>
<span class="sd">    plume as a function of the state space.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    z0 : float</span>
<span class="sd">        Initial depth (m) of the outer plume</span>
<span class="sd">    y0 : ndarray</span>
<span class="sd">        Initial values for the outer plume state space.</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>
<span class="sd">    p : `ModelParams` object</span>
<span class="sd">        Object containing the fixed model parameters for the stratified</span>
<span class="sd">        plume model.</span>
<span class="sd">    chem_names : str list</span>
<span class="sd">        List of chemical names to track for the dissolution.</span>
<span class="sd">    bi : float</span>
<span class="sd">        Half-width of the inner plume (m)</span>

<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    chem_names : str list</span>
<span class="sd">        List is dissolved chemical species to track</span>
<span class="sd">    len : int</span>
<span class="sd">        Number of dependent state space variables</span>
<span class="sd">    nchems : int</span>
<span class="sd">        Number of chemical species to track for the dissolution</span>
<span class="sd">    z : float</span>
<span class="sd">        Current value of the depth (m)</span>
<span class="sd">    y : ndarray</span>
<span class="sd">        Current value of the state space vector</span>
<span class="sd">    Q : float</span>
<span class="sd">        Volume flux of outer plume fluid (m^3/s)</span>
<span class="sd">    J : float</span>
<span class="sd">        Momentum flux of outer plume fluid (m^3/s)</span>
<span class="sd">    S : float</span>
<span class="sd">        Salinity flux in the outer plume (psu m^3/s)</span>
<span class="sd">    H : float</span>
<span class="sd">        Heat flux in the outer plume (J/s)</span>
<span class="sd">    C : ndarray</span>
<span class="sd">    Mass flux of dissolved species in the outer plume (kg/s)</span>
<span class="sd">    Ta : float</span>
<span class="sd">        Ambient temperature outside the plume (K)</span>
<span class="sd">    Sa : float</span>
<span class="sd">        Ambient salinity outside the plume (psu)</span>
<span class="sd">    P : float</span>
<span class="sd">        Local pressure (Pa)</span>
<span class="sd">    rho_a : float</span>
<span class="sd">        Ambient density outside the plume (kg/m^3)</span>
<span class="sd">    ca : ndarray</span>
<span class="sd">        Ambient concentrations outside the plume (kg/m^3)</span>
<span class="sd">    u : float</span>
<span class="sd">        Velocity of the outer plume (m/s)</span>
<span class="sd">    b : float</span>
<span class="sd">        Half-width of the outer plume (m)</span>
<span class="sd">    s : float</span>
<span class="sd">        Salinity of the outer plume continuous phase fluid (psu)</span>
<span class="sd">    T : float</span>
<span class="sd">        Temperature of the outer plume continous phase fluid (K)</span>
<span class="sd">    c : ndarray</span>
<span class="sd">        Concentration of dissolved species in the outer plume fluid (kg/m^2)</span>
<span class="sd">    rho : float</span>
<span class="sd">        Density of the outer plume continuous phase fluid (kg/m^3)</span>

<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="OuterPlume.__init__"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.OuterPlume.html#stratified_plume_model.OuterPlume.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">chem_names</span><span class="p">,</span> <span class="n">bi</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">OuterPlume</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="c1"># Store the input variables that will stay with the outer plume</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">z0</span> <span class="o">=</span> <span class="n">z0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">y0</span> <span class="o">=</span> <span class="n">y0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span> <span class="o">=</span> <span class="n">chem_names</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">len</span> <span class="o">=</span> <span class="n">y0</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nchems</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">chem_names</span><span class="p">)</span>

        <span class="c1"># Extract the state variables and compute the derived quantities</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">bi</span><span class="p">)</span></div>

<div class="viewcode-block" id="OuterPlume.update"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.OuterPlume.update.html#stratified_plume_model.OuterPlume.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">bi</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Update the `OuterPlume` object with the current local conditions</span>

<span class="sd">        Extract the state variables and compute the derived quantities given</span>
<span class="sd">        the current local conditions.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        z : float</span>
<span class="sd">            Local depth (m).</span>
<span class="sd">        y : ndarray</span>
<span class="sd">            Local values of the outer plume state space.</span>
<span class="sd">        profile : `ambient.Profile` object</span>
<span class="sd">            The ambient CTD object used by the simulation.</span>
<span class="sd">        p : `ModelParams` object</span>
<span class="sd">            Object containing the fixed model parameters for the stratified</span>
<span class="sd">            plume model.</span>
<span class="sd">        bi : float</span>
<span class="sd">            Inner plume half-width (m)</span>

<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        This method writes the `OuterPlume` object attributes `z`, `y`, `Q`,</span>
<span class="sd">        `J`, `S`, `H`, `C`, `Ta`, `Sa`, `P`, `rho_a`, `ca`, `u`, `b`, `s`,</span>
<span class="sd">        `T`, `c`, and `rho`.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Save the current state space</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">z</span> <span class="o">=</span> <span class="n">z</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">y</span>

        <span class="c1"># Extract the state-space variables from y</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">Q</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">J</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">S</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">H</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">C</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="mi">4</span><span class="p">:]</span>

        <span class="c1"># Get the local ambient conditions</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">Ta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Sa</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">P</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;temperature&#39;</span><span class="p">,</span>
                                   <span class="s1">&#39;salinity&#39;</span><span class="p">,</span> <span class="s1">&#39;pressure&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">rho_a</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Ta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Sa</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">P</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ca</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">chem_names</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span> <span class="o">&lt;</span> <span class="mf">0.</span><span class="p">:</span>
            <span class="c1"># Compute the continuous phase derived quantities</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">u</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">J</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Q</span><span class="o">**</span><span class="mi">2</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">J</span><span class="p">)</span> <span class="o">+</span> <span class="n">bi</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">S</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">T</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">H</span> <span class="o">/</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">rho_r</span> <span class="o">*</span> <span class="n">seawater</span><span class="o">.</span><span class="n">cp</span><span class="p">()</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">C</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">Q</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rho</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">s</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">P</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># There is no outer plume or the momentum is reversing</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">u</span> <span class="o">=</span> <span class="mf">0.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="mf">0.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">s</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Sa</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">T</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Ta</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ca</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rho</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rho_a</span></div></div>


<span class="c1"># ----------------------------------------------------------------------------</span>
<span class="c1"># Integration controllers</span>
<span class="c1"># ----------------------------------------------------------------------------</span>

<div class="viewcode-block" id="inner_main"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.inner_main.html#stratified_plume_model.inner_main">[docs]</a><span class="k">def</span> <span class="nf">inner_main</span><span class="p">(</span><span class="n">yi</span><span class="p">,</span> <span class="n">yo</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">,</span> <span class="n">delta_z</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Manage the integration of the inner plume</span>

<span class="sd">    Calculates the inner plume solution, creates the appropriate `neighbor`</span>
<span class="sd">    interpolation object, and returns the complete solution</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    yi : `InnerPlume` object</span>
<span class="sd">        Object containing the inner plume state space and methods to extract</span>
<span class="sd">        the state space variables</span>
<span class="sd">    yo : `OuterPlume` object</span>
<span class="sd">        Object containing the outer plume state space and methods to extract</span>
<span class="sd">        the state space variables</span>
<span class="sd">    particles : list of `dispersed_phases.PlumeParticle` objects</span>
<span class="sd">        List of `dispersed_phases.PlumeParticle` objects containing the</span>
<span class="sd">        dispersed phase local conditions and behavior.</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>
<span class="sd">    p : `ModelParams` object</span>
<span class="sd">        Object containing the fixed model parameters for the stratified</span>
<span class="sd">        plume model.</span>
<span class="sd">    neighbor : `scipy.interpolate.interp1d` object</span>
<span class="sd">        Container holding the latest solution for the outer plume state</span>
<span class="sd">        space</span>
<span class="sd">    delta_z : float</span>
<span class="sd">        Maximum step size to use in the simulation (m).  The ODE solver</span>
<span class="sd">        in `calculate` is set up with adaptive step size integration, so</span>
<span class="sd">        in theory this value determines the largest step size in the</span>
<span class="sd">        output data, but not the numerical stability of the calculation.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    z : ndarray</span>
<span class="sd">        Vector of elevations where the inner plume solution is obtained (m)</span>
<span class="sd">    y : ndarray</span>
<span class="sd">        Matrix of inner plume state space solutions.  Each row corresponds to</span>
<span class="sd">        a depth in z</span>
<span class="sd">    neighbor : `scipy.interpolate.interp1d` object</span>
<span class="sd">        An updated neighbor interpolation object with the inner plume solution</span>
<span class="sd">        ready to use with integration of the outer plume</span>

<span class="sd">    Notes</span>
<span class="sd">    -----</span>
<span class="sd">    With the Crounse (2000) continuous peeling term, the inner plume can</span>
<span class="sd">    integrate from the initial conditions to the free surface or top of a</span>
<span class="sd">    dissolving plume without stopping--there are no discontinuities in the</span>
<span class="sd">    solution.  Hence, no iteration loop is required for the inner plume</span>
<span class="sd">    integration.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Initialize the inner and outer plume objects with the conditions at the</span>
    <span class="c1"># base of the plume (needed for later iterations)</span>
    <span class="n">yi</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">yi</span><span class="o">.</span><span class="n">z0</span><span class="p">,</span> <span class="n">yi</span><span class="o">.</span><span class="n">y0</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
    <span class="n">yo</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">yo</span><span class="o">.</span><span class="n">z0</span><span class="p">,</span> <span class="n">yo</span><span class="o">.</span><span class="n">y0</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">yi</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>

    <span class="c1"># Integrate up the inner plume using the double plume integral model</span>
    <span class="n">z</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">smp</span><span class="o">.</span><span class="n">calculate</span><span class="p">(</span><span class="n">yi</span><span class="p">,</span> <span class="n">yo</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">,</span>
                          <span class="n">smp</span><span class="o">.</span><span class="n">derivs_inner</span><span class="p">,</span> <span class="n">yi</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="n">yi</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.</span><span class="p">,</span> <span class="n">delta_z</span><span class="p">)</span>

    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;  Done with inner plume calculations...&#39;</span><span class="p">)</span>

    <span class="c1"># Update yi and build the neighbor matrix</span>
    <span class="n">yi</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">z</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,:],</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
    <span class="n">neighbor</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">z</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">transpose</span><span class="p">())</span>

    <span class="k">return</span> <span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">)</span></div>

<div class="viewcode-block" id="outer_main"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.outer_main.html#stratified_plume_model.outer_main">[docs]</a><span class="k">def</span> <span class="nf">outer_main</span><span class="p">(</span><span class="n">yi</span><span class="p">,</span> <span class="n">yo</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">,</span> <span class="n">delta_z</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Manage the integration of the outer plume segments</span>

<span class="sd">    Calculates the outer plume solution, creates the appropriate `neighbor`</span>
<span class="sd">    interpolation object, and returns the complete solution</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    yi : `InnerPlume` object</span>
<span class="sd">        Object containing the inner plume state space and methods to extract</span>
<span class="sd">        the state space variables.</span>
<span class="sd">    yo : `OuterPlume` object</span>
<span class="sd">        Object containing the outer plume state space and methods to extract</span>
<span class="sd">        the state space variables.</span>
<span class="sd">    particles : list of `dispersed_phases.PlumeParticle` objects</span>
<span class="sd">        List of `dispersed_phases.PlumeParticle` objects containing the</span>
<span class="sd">        dispersed phase local conditions and behavior.</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>
<span class="sd">    p : `ModelParams` object</span>
<span class="sd">        Object containing the fixed model parameters for the stratified</span>
<span class="sd">        plume model.</span>
<span class="sd">    neighbor : `scipy.interpolate.interp1d` object</span>
<span class="sd">        Container holding the latest solution for the inner plume state</span>
<span class="sd">        space.</span>
<span class="sd">    delta_z : float</span>
<span class="sd">        Maximum step size to use in the simulation (m).  The ODE solver</span>
<span class="sd">        in `calculate` is set up with adaptive step size integration, so</span>
<span class="sd">        in theory this value determines the largest step size in the</span>
<span class="sd">        output data, but not the numerical stability of the calculation.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    z : ndarray</span>
<span class="sd">        Vector of elevations where the outer plume solution is obtained (m).</span>
<span class="sd">    y : ndarray</span>
<span class="sd">        Matrix of outer plume state space solutions.  Each row corresponds to</span>
<span class="sd">        a depth in z.</span>
<span class="sd">    neighbor : `scipy.interpolate.interp1d` object</span>
<span class="sd">        An updated neighbor interpolation object with the outer plume solution</span>
<span class="sd">        ready to use with integration of the inner plume.</span>

<span class="sd">    Notes</span>
<span class="sd">    -----</span>
<span class="sd">    There can be many outer plume segments, each associated with a localized,</span>
<span class="sd">    intense area of detrainment from the inner plume.  Each of these outer</span>
<span class="sd">    plume segments generally stop at a level of neutral buoyancy before</span>
<span class="sd">    reaching the next segment, so they will each need to have an independent</span>
<span class="sd">    integration.  Thus, this function contains an iteration loop that</span>
<span class="sd">    terminates when the plume has been integrated from the top to the bottom</span>
<span class="sd">    of the inner plume.</span>

<span class="sd">    Once an outer plume segment stops at a level of neutral buoyancy, this</span>
<span class="sd">    function searches for the next outer plume by collecting detrained fluid</span>
<span class="sd">    over a length of inner plume equal to `nwidths` times the half-width and</span>
<span class="sd">    attempts to start an integration.  If the negative buoyancy of that</span>
<span class="sd">    fluid is inadequate to overcome the upward drag of the inner plume, then</span>
<span class="sd">    the outer plume is said to be &quot;not viable,&quot; and the algorithm attemps to</span>
<span class="sd">    do this again with the next `nwidths` of detrained water.  Once the</span>
<span class="sd">    outer plume segment becomes viable, those initial conditions are passed</span>
<span class="sd">    to the `smp.calculate` function, and the outer plume is integrated to</span>
<span class="sd">    neutral buoyancy.  This succession of steps repeats until the bottom of</span>
<span class="sd">    the inner plume is reached.</span>

<span class="sd">    When dissolution in the inner plume is large enough that the detained</span>
<span class="sd">    fluid is heavier than ambient (e.g., enriched by CO2 such that the</span>
<span class="sd">    solution is not dilute), then outer plume segments can tend to overlap.</span>
<span class="sd">    In this case, also, the lowest outer plume segment may descend beyond</span>
<span class="sd">    the starting point of the inner plume.  This function assumes that the</span>
<span class="sd">    bottom of the CTD cast indicates the sea floor; hence, integration</span>
<span class="sd">    always stops at the sea bottom.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Get the initial conditions for the top of the plume</span>
    <span class="k">if</span> <span class="n">yi</span><span class="o">.</span><span class="n">z</span> <span class="o">&lt;=</span> <span class="mf">0.</span><span class="p">:</span>
        <span class="c1"># The inner plume hit the free surface</span>
        <span class="n">yi</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="mf">0.</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">(</span><span class="mf">0.</span><span class="p">),</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
        <span class="n">z0</span><span class="p">,</span> <span class="n">y0</span> <span class="o">=</span> <span class="n">smp</span><span class="o">.</span><span class="n">outer_surf</span><span class="p">(</span><span class="n">yi</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c1"># The inner plume stopped because it fully dissolved</span>
        <span class="n">z_0</span> <span class="o">=</span> <span class="n">yi</span><span class="o">.</span><span class="n">z</span>
        <span class="n">z0</span><span class="p">,</span> <span class="n">y0</span> <span class="o">=</span> <span class="n">smp</span><span class="o">.</span><span class="n">outer_dis</span><span class="p">(</span><span class="n">yi</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">,</span> <span class="n">z_0</span><span class="p">)</span>

    <span class="c1"># Initialize the outer plume object with these initial conditions</span>
    <span class="n">yi</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">(</span><span class="n">z0</span><span class="p">),</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
    <span class="n">yo</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">yi</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>

    <span class="c1"># Integrate down the first outer plume segment</span>
    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">    Top outer plume...&#39;</span>       <span class="p">)</span>
    <span class="n">z</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">smp</span><span class="o">.</span><span class="n">calculate</span><span class="p">(</span><span class="n">yi</span><span class="p">,</span> <span class="n">yo</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">,</span>
                          <span class="n">smp</span><span class="o">.</span><span class="n">derivs_outer</span><span class="p">,</span> <span class="n">yo</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="n">yo</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">profile</span><span class="o">.</span><span class="n">z_max</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span>
                          <span class="n">delta_z</span><span class="p">)</span>

    <span class="c1"># Start building the complete solution for the outer plume</span>
    <span class="n">z_sol</span> <span class="o">=</span> <span class="n">z</span>
    <span class="n">y_sol</span> <span class="o">=</span> <span class="n">y</span>

    <span class="c1"># Record the depth of the current calculations and the bottom of the</span>
    <span class="c1"># inner plume</span>
    <span class="n">z_depth</span> <span class="o">=</span> <span class="n">z</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">z_source</span> <span class="o">=</span> <span class="n">yi</span><span class="o">.</span><span class="n">z0</span>

    <span class="c1"># Integrate down to the bottom of the inner plume and continue until the</span>
    <span class="c1"># outer plume stops or reaches the bottom of the reservoir</span>
    <span class="n">k</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="k">while</span> <span class="n">z_depth</span> <span class="o">&lt;</span> <span class="n">z_source</span><span class="p">:</span>

        <span class="c1"># Get the initial conditions for the next outer plume segment</span>
        <span class="n">z0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="n">flag</span> <span class="o">=</span> <span class="n">smp</span><span class="o">.</span><span class="n">outer_cpic</span><span class="p">(</span><span class="n">yi</span><span class="p">,</span> <span class="n">yo</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span>
                                       <span class="n">neighbor</span><span class="p">,</span> <span class="n">z_depth</span><span class="p">)</span>

        <span class="c1"># Integrate the outer plume if it is viable</span>
        <span class="k">if</span> <span class="n">flag</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">:</span>
            <span class="c1"># Integrate the outer plume</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;    - Outer plume </span><span class="si">%2.2d</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">k</span><span class="p">)</span>
            <span class="n">k</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="c1"># Initialize the outer plume object with these initial conditions</span>
            <span class="n">yi</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">(</span><span class="n">z0</span><span class="p">),</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
            <span class="n">yo</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="n">y0</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">yi</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>

            <span class="c1"># Integrate down the this outer plume segment</span>
            <span class="n">z</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">smp</span><span class="o">.</span><span class="n">calculate</span><span class="p">(</span><span class="n">yi</span><span class="p">,</span> <span class="n">yo</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">,</span>
                                  <span class="n">smp</span><span class="o">.</span><span class="n">derivs_outer</span><span class="p">,</span> <span class="n">yo</span><span class="o">.</span><span class="n">z</span><span class="p">,</span> <span class="n">yo</span><span class="o">.</span><span class="n">y</span><span class="p">,</span>
                                  <span class="n">profile</span><span class="o">.</span><span class="n">z_max</span><span class="p">,</span> <span class="mf">1.</span><span class="p">,</span> <span class="n">delta_z</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># This intermediate peel is not viable</span>
            <span class="n">z</span> <span class="o">=</span> <span class="n">z0</span>
            <span class="n">y</span> <span class="o">=</span> <span class="n">y0</span>

        <span class="c1"># Add the latest iteration to the outer plume solution</span>
        <span class="n">z_sol</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">z_sol</span><span class="p">,</span> <span class="n">z</span><span class="p">))</span>
        <span class="n">y_sol</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">y_sol</span><span class="p">,</span> <span class="n">y</span><span class="p">))</span>

        <span class="c1"># Update the current depth</span>
        <span class="n">z_depth</span> <span class="o">=</span> <span class="n">z_sol</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;  Done with outer plume calculations...&#39;</span><span class="p">)</span>

    <span class="c1"># Build the neighbor matrix</span>
    <span class="n">neighbor</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">(</span><span class="n">z_sol</span><span class="p">,</span> <span class="n">y_sol</span><span class="o">.</span><span class="n">transpose</span><span class="p">())</span>

    <span class="k">return</span> <span class="p">(</span><span class="n">z_sol</span><span class="p">,</span> <span class="n">y_sol</span><span class="p">,</span> <span class="n">neighbor</span><span class="p">)</span></div>

<div class="viewcode-block" id="err_check"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.err_check.html#stratified_plume_model.err_check">[docs]</a><span class="k">def</span> <span class="nf">err_check</span><span class="p">(</span><span class="n">zi</span><span class="p">,</span> <span class="n">yi</span><span class="p">,</span> <span class="n">zo</span><span class="p">,</span> <span class="n">yo</span><span class="p">,</span> <span class="n">zi_old</span><span class="p">,</span> <span class="n">yi_old</span><span class="p">,</span> <span class="n">zo_old</span><span class="p">,</span> <span class="n">yo_old</span><span class="p">,</span> <span class="n">yi_local</span><span class="p">,</span>
              <span class="n">yo_local</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Computes the error between two solutions of the state space.</span>

<span class="sd">    Compares two state space solutions and returns the maximum relative error</span>
<span class="sd">    among a suite of error tests that include state space variable magnitudes</span>
<span class="sd">    as well as geometric scales (intrusion and peel depths, etc.).</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    zi : ndarray</span>
<span class="sd">        Vector of depths for the inner plume solution (m).</span>
<span class="sd">    yi : ndarray</span>
<span class="sd">        Matrix of inner plume state space variables, each row corresponding</span>
<span class="sd">        to a depth in `zi`.</span>
<span class="sd">    zo : ndarray</span>
<span class="sd">        Vector of depths for the outer plume solution (m).</span>
<span class="sd">    yo : ndarray</span>
<span class="sd">        Matrix of outer plume state space variables, each row corresponding</span>
<span class="sd">        to a depth in `zo`.</span>
<span class="sd">    zi_old : ndarray</span>
<span class="sd">        Values of `zi` for the previous iteration.</span>
<span class="sd">    yi_old : ndarray</span>
<span class="sd">        Values of `yi` for the previous iteration.</span>
<span class="sd">    zo_old : ndarray</span>
<span class="sd">        Values of `zo` for the previous iteration.</span>
<span class="sd">    yo_old : ndarray</span>
<span class="sd">        Values of `yo` for the previous iteration.</span>
<span class="sd">    yi_local : `InnerPlume` object</span>
<span class="sd">        Object containing the inner plume state space and methods to extract</span>
<span class="sd">        the state space variables</span>
<span class="sd">    yo_local : `OuterPlume` object</span>
<span class="sd">        Object containing the outer plume state space and methods to extract</span>
<span class="sd">        the state space variables</span>
<span class="sd">    particles : list of `dispersed_phases.PlumeParticle` objects</span>
<span class="sd">        List of `dispersed_phases.PlumeParticle` objects containing the</span>
<span class="sd">        dispersed phase local conditions and behavior.</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>
<span class="sd">    p : `ModelParams` object</span>
<span class="sd">        Object containing the fixed model parameters for the stratified</span>
<span class="sd">        plume model.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    ea : float</span>
<span class="sd">        Maximum value of the relative error for the given error tests.</span>

<span class="sd">    Notes</span>
<span class="sd">    -----</span>
<span class="sd">    The error statistics are computed for the peel heights, trap heights,</span>
<span class="sd">    intrusion layer fluxes, inner plume flux at the base of each intrusion</span>
<span class="sd">    layer, the maximum flow rates, and maximum momentum fluxes, and the</span>
<span class="sd">    total height of the plume.  The largest absolute relative error is</span>
<span class="sd">    returned.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">metrics</span><span class="p">(</span><span class="n">zi</span><span class="p">,</span> <span class="n">yi</span><span class="p">,</span> <span class="n">zo</span><span class="p">,</span> <span class="n">yo</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the characteristic plume scales</span>

<span class="sd">        Compute the characteristic plume length and flow rate scales from a</span>
<span class="sd">        given state space solution.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        zi : ndarray</span>
<span class="sd">            Inner plume solution heights (m)</span>
<span class="sd">        yi : ndarray</span>
<span class="sd">            Inner plume state space solution</span>
<span class="sd">        zo : ndarray</span>
<span class="sd">            Outer plume solution heights (m)</span>
<span class="sd">        yo : ndarray</span>
<span class="sd">            Outer plume state space solution</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        hp : ndarray</span>
<span class="sd">            Peel heights (m)</span>
<span class="sd">        ht : ndarray</span>
<span class="sd">            Trap heights (m)</span>
<span class="sd">        qi : ndarray</span>
<span class="sd">            Intrusion layer flow rates (m^3/s)</span>
<span class="sd">        q : ndarray</span>
<span class="sd">            Inner plume flow rates, Q1 (m^3/s)</span>

<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        The algorithm in this method starts at the top peel and works its</span>
<span class="sd">        way down the outer plumes to find all the peels.  We return the</span>
<span class="sd">        results flipped up/down so that the first element of each returned</span>
<span class="sd">        array will the data for the lowest peel, and the elements at the</span>
<span class="sd">        top will be for the highest peel.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Find each of the peels</span>
        <span class="n">p_top</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">p_bot</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">peels</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">peel</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">yo</span><span class="p">[:,</span><span class="mi">0</span><span class="p">])):</span>
            <span class="k">if</span> <span class="n">peel</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">yo</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span> <span class="o">&gt;</span> <span class="mf">0.</span><span class="p">:</span>
                <span class="c1"># This is the top of a new peel</span>
                <span class="n">peel</span> <span class="o">=</span> <span class="mi">1</span>
                <span class="n">p_top</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
                <span class="n">peels</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">if</span> <span class="n">peel</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">yo</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="c1"># this is the bottom of the current peel</span>
                <span class="n">peel</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="n">p_bot</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">peel</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="c1"># Need to close the last peel</span>
            <span class="n">peel</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">p_bot</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="n">p_top</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">p_top</span><span class="p">)</span>
        <span class="n">p_bot</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">p_bot</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">peels</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># Get all the peel heights</span>
            <span class="n">hp</span> <span class="o">=</span> <span class="n">zi</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">zo</span><span class="p">[</span><span class="n">p_top</span><span class="p">]</span>

            <span class="c1"># Get all the heights at the bottom of each intrusion</span>
            <span class="n">ht</span> <span class="o">=</span> <span class="n">zi</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">zo</span><span class="p">[</span><span class="n">p_bot</span><span class="p">]</span>

            <span class="c1"># Get the intrusion layer fluxes</span>
            <span class="n">qi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">peels</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">peels</span><span class="p">):</span>
                <span class="n">qi</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yo</span><span class="p">[</span><span class="n">p_top</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">:</span> <span class="n">p_bot</span><span class="p">[</span><span class="n">i</span><span class="p">]])</span>

            <span class="c1"># Get the volume flux at the bottom of each intrusion layer</span>
            <span class="n">y_inner</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">zi</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">yi</span><span class="p">)</span><span class="o">.</span><span class="n">transpose</span><span class="p">(),</span>
                      <span class="n">fill_value</span><span class="o">=</span><span class="s1">&#39;extrapolate&#39;</span><span class="p">)</span>
            <span class="n">q</span> <span class="o">=</span> <span class="n">y_inner</span><span class="p">(</span><span class="n">zi</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">ht</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># There were not peels</span>
            <span class="n">hp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.</span><span class="p">])</span>
            <span class="n">ht</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.</span><span class="p">])</span>
            <span class="n">qi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.</span><span class="p">])</span>
            <span class="n">q</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.</span><span class="p">])</span>

        <span class="k">return</span> <span class="p">(</span><span class="n">peels</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">hp</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">ht</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">qi</span><span class="p">),</span>
            <span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">q</span><span class="p">))</span>

    <span class="c1"># Find the characteristic plume scales</span>
    <span class="n">peels</span><span class="p">,</span> <span class="n">hp</span><span class="p">,</span> <span class="n">ht</span><span class="p">,</span> <span class="n">qi</span><span class="p">,</span> <span class="n">q</span> <span class="o">=</span> <span class="n">metrics</span><span class="p">(</span><span class="n">zi</span><span class="p">,</span> <span class="n">yi</span><span class="p">,</span> <span class="n">zo</span><span class="p">,</span> <span class="n">yo</span><span class="p">)</span>
    <span class="n">peels_old</span><span class="p">,</span> <span class="n">hp_old</span><span class="p">,</span> <span class="n">ht_old</span><span class="p">,</span> <span class="n">qi_old</span><span class="p">,</span> <span class="n">q_old</span> <span class="o">=</span> <span class="n">metrics</span><span class="p">(</span><span class="n">zi_old</span><span class="p">,</span> <span class="n">yi_old</span><span class="p">,</span>
        <span class="n">zo_old</span><span class="p">,</span> <span class="n">yo_old</span><span class="p">)</span>

    <span class="c1"># Compute the error statistics</span>
    <span class="n">ea</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="c1"># Peel characteristics</span>
    <span class="k">if</span> <span class="n">peels</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">peels</span><span class="p">,</span> <span class="n">peels_old</span><span class="p">]))</span>
        <span class="n">hp_ea</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">((</span><span class="n">hp</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">]</span> <span class="o">-</span> <span class="n">hp_old</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">])</span> <span class="o">/</span> <span class="n">hp</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">]))</span>
        <span class="n">ht_ea</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">((</span><span class="n">ht</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">]</span> <span class="o">-</span> <span class="n">ht_old</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">])</span> <span class="o">/</span> <span class="n">ht</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">]))</span>
        <span class="n">qi_ea</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">((</span><span class="n">qi</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">]</span> <span class="o">-</span> <span class="n">qi_old</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">])</span> <span class="o">/</span> <span class="n">qi</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">]))</span>
        <span class="n">q_ea</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">((</span><span class="n">q</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">]</span> <span class="o">-</span> <span class="n">q_old</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">])</span> <span class="o">/</span> <span class="n">q</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="n">p</span><span class="p">]))</span>
        <span class="n">ea</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">hp_ea</span><span class="p">))</span>
        <span class="n">ea</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">ht_ea</span><span class="p">))</span>
        <span class="n">ea</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">qi_ea</span><span class="p">))</span>
        <span class="n">ea</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">q_ea</span><span class="p">))</span>

    <span class="c1"># Volume flux maxima</span>
    <span class="n">Qi_ea</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yi</span><span class="p">[:,</span><span class="mi">0</span><span class="p">])</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yi_old</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]))</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yi</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]))</span>
    <span class="n">Qo_ea</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="o">-</span><span class="n">yo</span><span class="p">[:,</span><span class="mi">0</span><span class="p">])</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="o">-</span><span class="n">yo_old</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]))</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="o">-</span><span class="n">yo</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]))</span>
    <span class="n">ea</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Qi_ea</span><span class="p">)</span>
    <span class="n">ea</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Qo_ea</span><span class="p">)</span>

    <span class="c1"># Momentum flux maxima</span>
    <span class="n">Ji_ea</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yi</span><span class="p">[:,</span><span class="mi">1</span><span class="p">])</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yi_old</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]))</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yi</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]))</span>
    <span class="n">Jo_ea</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yo</span><span class="p">[:,</span><span class="mi">1</span><span class="p">])</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yo_old</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]))</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">yo</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]))</span>
    <span class="n">ea</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Ji_ea</span><span class="p">)</span>
    <span class="n">ea</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Jo_ea</span><span class="p">)</span>

    <span class="c1"># The height of the inner plume</span>
    <span class="n">Hi</span> <span class="o">=</span> <span class="n">zi</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">zi</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">Hi_old</span> <span class="o">=</span> <span class="n">zi_old</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">zi_old</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">H_ea</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">((</span><span class="n">Hi</span> <span class="o">-</span> <span class="n">Hi_old</span><span class="p">)</span> <span class="o">/</span> <span class="n">Hi</span><span class="p">)</span>
    <span class="n">ea</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">H_ea</span><span class="p">)</span>

    <span class="c1"># Return the largest error term</span>
    <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">ea</span><span class="p">)</span></div>

<span class="c1"># ----------------------------------------------------------------------------</span>
<span class="c1"># Helper functions</span>
<span class="c1"># ----------------------------------------------------------------------------</span>

<div class="viewcode-block" id="particle_from_Q"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.particle_from_Q.html#stratified_plume_model.particle_from_Q">[docs]</a><span class="k">def</span> <span class="nf">particle_from_Q</span><span class="p">(</span><span class="n">profile</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">dbm_particle</span><span class="p">,</span> <span class="n">yk</span><span class="p">,</span> <span class="n">Q_N</span><span class="p">,</span> <span class="n">de</span><span class="p">,</span> <span class="n">lambda_1</span><span class="p">,</span> <span class="n">T0</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                    <span class="n">K</span><span class="o">=</span><span class="mf">1.</span><span class="p">,</span> <span class="n">K_T</span><span class="o">=</span><span class="mf">1.</span><span class="p">,</span> <span class="n">fdis</span><span class="o">=</span><span class="mf">1.e-6</span><span class="p">,</span> <span class="n">t_hyd</span><span class="o">=</span><span class="mf">0.</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Create a `dispersed_phases.PlumeParticle` object from volume flux</span>

<span class="sd">    Returns a `dispered_phases.PlumeParticle` object given the particle</span>
<span class="sd">    attributes and the initial total volume flux at standard conditions.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>
<span class="sd">    z0 : float</span>
<span class="sd">        Depth of the release point (m)</span>
<span class="sd">    dbm_particle : `dbm.FluidParticle` or `dbm.InsolubleParticle` object</span>
<span class="sd">        Object describing the particle properties and behavior</span>
<span class="sd">    yk : ndarray</span>
<span class="sd">        Vector of mol fractions of each component of the dispersed phase</span>
<span class="sd">        particle.  If the particle is a `dbm.InsolubleParticle`, then yk</span>
<span class="sd">        should be equal to one.</span>
<span class="sd">    Q_N : float</span>
<span class="sd">        Volume flux (m^3/s) at standard conditions, defined as 0 deg C and</span>
<span class="sd">        1 bar</span>
<span class="sd">    de : float</span>
<span class="sd">        Initial diameter (m) of the particle</span>
<span class="sd">    lambda_1 : float</span>
<span class="sd">        spreading rate of the dispersed phase in a plume (--)</span>
<span class="sd">    T0 : float, default = None</span>
<span class="sd">        Initial temperature of the of `dbm` particle object (K).  If None,</span>
<span class="sd">        then T0 is set equal to the ambient temperature.</span>
<span class="sd">    K : float, default = 1.</span>
<span class="sd">        Mass transfer reduction factor (--).</span>
<span class="sd">    K_T : float, default = 1.</span>
<span class="sd">        Heat transfer reduction factor (--).</span>
<span class="sd">    fdis : float, default = 0.01</span>
<span class="sd">        Fraction of the initial total mass (--) remaining when the particle</span>
<span class="sd">        should be considered dissolved.</span>
<span class="sd">    t_hyd : float, default = 0.</span>
<span class="sd">        Hydrate film formation time (s).  Mass transfer is computed by clean</span>
<span class="sd">        bubble methods for t less than t_hyd and by dirty bubble methods</span>
<span class="sd">        thereafter.  The default behavior is to assume the particle is dirty</span>
<span class="sd">        or hydrate covered from the release.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    particle : dispersed_phases.PlumeParticle object</span>
<span class="sd">        A `dispersed_phases.PlumeParticle` object containing the initial</span>
<span class="sd">        conditions for the given particle in the simulation</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Convert the flow rate and diameter to the state variables of a</span>
    <span class="c1"># dispersed_phases.PlumeParticle object</span>
    <span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">nb0</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span> <span class="o">=</span> <span class="n">dispersed_phases</span><span class="o">.</span><span class="n">initial_conditions</span><span class="p">(</span>
        <span class="n">profile</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">dbm_particle</span><span class="p">,</span> <span class="n">yk</span><span class="p">,</span> <span class="n">Q_N</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">de</span><span class="p">,</span> <span class="n">T0</span><span class="p">)</span>

    <span class="c1"># Create the particle object</span>
    <span class="k">return</span> <span class="n">dispersed_phases</span><span class="o">.</span><span class="n">PlumeParticle</span><span class="p">(</span><span class="n">dbm_particle</span><span class="p">,</span> <span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">nb0</span><span class="p">,</span> <span class="n">lambda_1</span><span class="p">,</span>
                                          <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="n">K</span><span class="p">,</span> <span class="n">K_T</span><span class="p">,</span> <span class="n">fdis</span><span class="p">,</span> <span class="n">t_hyd</span><span class="p">)</span></div>

<div class="viewcode-block" id="particle_from_mb0"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.particle_from_mb0.html#stratified_plume_model.particle_from_mb0">[docs]</a><span class="k">def</span> <span class="nf">particle_from_mb0</span><span class="p">(</span><span class="n">profile</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">dbm_particle</span><span class="p">,</span> <span class="n">yk</span><span class="p">,</span> <span class="n">mb0</span><span class="p">,</span> <span class="n">de</span><span class="p">,</span> <span class="n">lambda_1</span><span class="p">,</span>
                      <span class="n">T0</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">K</span><span class="o">=</span><span class="mf">1.</span><span class="p">,</span> <span class="n">K_T</span><span class="o">=</span><span class="mf">1.</span><span class="p">,</span> <span class="n">fdis</span><span class="o">=</span><span class="mf">1.e-6</span><span class="p">,</span> <span class="n">t_hyd</span><span class="o">=</span><span class="mf">0.</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Create a `dispersed_phases.PlumeParticle` object from the mass flux</span>

<span class="sd">    Returns a `dispersed_phases.PlumeParticle` object given the particle</span>
<span class="sd">    attributes and the initial total mass flux at the source.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation</span>
<span class="sd">    z0 : float</span>
<span class="sd">        Depth of the release point (m)</span>
<span class="sd">    dbm_particle : `dbm.FluidParticle` or `dbm.InsolubleParticle` object</span>
<span class="sd">        Object describing the particle properties and behavior</span>
<span class="sd">    yk : ndarray</span>
<span class="sd">        Vector of mol fractions of each component of the dispersed phase</span>
<span class="sd">        particle.  If the particle is a `dbm.InsolubleParticle`, then yk</span>
<span class="sd">        should be equal to one.</span>
<span class="sd">    mb0 : float</span>
<span class="sd">        Mass flux (kg/s) of all particle components together at the release</span>
<span class="sd">        points</span>
<span class="sd">    de : float</span>
<span class="sd">        Initial diameter (m) of the particle</span>
<span class="sd">    lambda_1 : float</span>
<span class="sd">        Spreading rate of the dispersed phase in a plume (--)</span>
<span class="sd">    T0 : float, default = None</span>
<span class="sd">        Initial temperature of the of `dbm` particle object (K).  If None,</span>
<span class="sd">        then T0 is set equal to the ambient temperature.</span>
<span class="sd">    K : float, default = 1.</span>
<span class="sd">        Mass transfer reduction factor (--).</span>
<span class="sd">    K_T : float, default = 1.</span>
<span class="sd">        Heat transfer reduction factor (--).</span>
<span class="sd">    fdis : float, default = 1.e-6</span>
<span class="sd">        Fraction of the initial total mass (--) remaining when the particle</span>
<span class="sd">        should be considered dissolved.</span>
<span class="sd">    t_hyd : float, default = 0.</span>
<span class="sd">        Hydrate film formation time (s).  Mass transfer is computed by clean</span>
<span class="sd">        bubble methods for t less than t_hyd and by dirty bubble methods</span>
<span class="sd">        thereafter.  The default behavior is to assume the particle is dirty</span>
<span class="sd">        or hydrate covered from the release.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    particle : dispersed_phases.PlumeParticle object</span>
<span class="sd">        A `dispersed_phases.PlumeParticle` object containing the initial</span>
<span class="sd">        conditions for the given particle in the simulation</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Convert the mass flux and diameter to the state variables of a</span>
    <span class="c1"># dispersed_phases.PlumeParticle object</span>
    <span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">nb0</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span> <span class="o">=</span> <span class="n">dispersed_phases</span><span class="o">.</span><span class="n">initial_conditions</span><span class="p">(</span>
        <span class="n">profile</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">dbm_particle</span><span class="p">,</span> <span class="n">yk</span><span class="p">,</span> <span class="n">mb0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">de</span><span class="p">,</span> <span class="n">T0</span><span class="p">)</span>

    <span class="c1"># Create the particle object</span>
    <span class="k">return</span> <span class="n">dispersed_phases</span><span class="o">.</span><span class="n">PlumeParticle</span><span class="p">(</span><span class="n">dbm_particle</span><span class="p">,</span> <span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">nb0</span><span class="p">,</span> <span class="n">lambda_1</span><span class="p">,</span>
                                          <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="n">K</span><span class="p">,</span> <span class="n">K_T</span><span class="p">,</span> <span class="n">fdis</span><span class="p">,</span> <span class="n">t_hyd</span><span class="p">)</span></div>

<div class="viewcode-block" id="plot_state_space"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.plot_state_space.html#stratified_plume_model.plot_state_space">[docs]</a><span class="k">def</span> <span class="nf">plot_state_space</span><span class="p">(</span><span class="n">zi</span><span class="p">,</span> <span class="n">yi</span><span class="p">,</span> <span class="n">zo</span><span class="p">,</span> <span class="n">yo</span><span class="p">,</span> <span class="n">yi_local</span><span class="p">,</span> <span class="n">yo_local</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span>
                     <span class="n">p</span><span class="p">,</span> <span class="n">fig</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Plot the state space for interrogation during model convergence</span>

<span class="sd">    Plot the simple state space variables volume flux, momentum flux, total</span>
<span class="sd">    particle mass flux, and dissolved component flux in order to observe</span>
<span class="sd">    changes during each step of model iteration.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    zi : ndarray</span>
<span class="sd">        Vector of depth for the inner plume solution (m).</span>
<span class="sd">    yi : ndarray</span>
<span class="sd">        Matrix of inner plume solutions, with each row corresponding to a</span>
<span class="sd">        depth in `zi`.</span>
<span class="sd">    zo : ndarray</span>
<span class="sd">        Vector of depth for the outer plume solution (m).</span>
<span class="sd">    yo : ndarray</span>
<span class="sd">        Matrix of outer plume solutions, with each row corresponding to a</span>
<span class="sd">        depth in `zo`.</span>
<span class="sd">    yi_local : `InnerPlume` object</span>
<span class="sd">        Inner plume object for extracting variables from the state space.</span>
<span class="sd">    yo_local : `OuterPlume` object</span>
<span class="sd">        Outer plume object for extracting variables from the state space.</span>
<span class="sd">    particles : list of `dispersed_phases.PlumeParticle` objects</span>
<span class="sd">        List of `dispersed_phases.PlumeParticle` objects containing the</span>
<span class="sd">        dispersed phase local conditions and behavior.</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>
<span class="sd">    p : `ModelParams` object</span>
<span class="sd">        Object containing the fixed model parameters for the stratified</span>
<span class="sd">        plume model.</span>
<span class="sd">    fig : int</span>
<span class="sd">        Figure number.  Number of the figure window in which to draw the plot.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">import</span> <span class="nn">matplotlib</span> <span class="k">as</span> <span class="nn">mpl</span>
    <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>

    <span class="c1"># Extract the inner plume variables to plot</span>
    <span class="n">Qi</span> <span class="o">=</span> <span class="n">yi</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">Ji</span> <span class="o">=</span> <span class="n">yi</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">idx</span> <span class="o">=</span> <span class="mi">4</span>
    <span class="n">Mp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">zi</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">np</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">yi_local</span><span class="o">.</span><span class="n">np</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">issoluble</span><span class="p">:</span>
            <span class="n">Mp</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">yi</span><span class="p">[:,</span> <span class="n">idx</span><span class="p">:</span><span class="n">idx</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">composition</span><span class="p">)],</span>
                             <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">composition</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">Mp</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">yi</span><span class="p">[:,</span> <span class="n">idx</span><span class="p">:</span><span class="n">idx</span><span class="o">+</span><span class="mi">1</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
            <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">idx</span> <span class="o">+=</span> <span class="mi">1</span>
    <span class="k">if</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">nchems</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">Ci</span> <span class="o">=</span> <span class="n">yi</span><span class="p">[:,</span><span class="n">idx</span><span class="p">:]</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">Ci</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">zi</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>

    <span class="c1"># Extract the outer plume variables to plot</span>
    <span class="n">Qo</span> <span class="o">=</span> <span class="n">yo</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">Jo</span> <span class="o">=</span> <span class="n">yo</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">if</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">nchems</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">Co</span> <span class="o">=</span> <span class="n">yo</span><span class="p">[:,</span><span class="mi">4</span><span class="p">:]</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">Co</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">zo</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>

    <span class="c1"># Plot the figures</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>

    <span class="c1"># Volume flux</span>
    <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">221</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Qi</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Qo</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Q (m^3/s)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Momentum flux</span>
    <span class="n">ax2</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">222</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Ji</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="o">-</span><span class="n">Jo</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;J (m^4/s^2)&#39;</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Mass fluxes</span>
    <span class="n">ax3</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">223</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Mp</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;M (kg/s)&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Dissolved component concentrations</span>
    <span class="n">ax4</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">224</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Ci</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Co</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;C (kg/s)&#39;</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="n">plt</span><span class="o">.</span><span class="n">draw</span><span class="p">()</span></div>

<div class="viewcode-block" id="plot_all_variables"><a class="viewcode-back" href="../autodoc/spm/stratified_plume_model.plot_all_variables.html#stratified_plume_model.plot_all_variables">[docs]</a><span class="k">def</span> <span class="nf">plot_all_variables</span><span class="p">(</span><span class="n">zi</span><span class="p">,</span> <span class="n">yi</span><span class="p">,</span> <span class="n">zo</span><span class="p">,</span> <span class="n">yo</span><span class="p">,</span> <span class="n">yi_local</span><span class="p">,</span> <span class="n">yo_local</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span>
                       <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">fig</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Plot the complete variable suite for model validation and interpretation</span>

<span class="sd">    Plot a complete suite of state and derived variables along with some</span>
<span class="sd">    key model parameters and environmental data.  These plots provide both</span>
<span class="sd">    validation that model calculations are within expected ranges and a clear</span>
<span class="sd">    presentation of the results to aid in model interpretation.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    zi : ndarray</span>
<span class="sd">        Vector of depth for the inner plume solution (m).</span>
<span class="sd">    yi : ndarray</span>
<span class="sd">        Matrix of inner plume solutions, with each row corresponding to a</span>
<span class="sd">        depth in `zi`.</span>
<span class="sd">    zo : ndarray</span>
<span class="sd">        Vector of depth for the outer plume solution (m).</span>
<span class="sd">    yo : ndarray</span>
<span class="sd">        Matrix of outer plume solutions, with each row corresponding to a</span>
<span class="sd">        depth in `zo`.</span>
<span class="sd">    yi_local : `InnerPlume` object</span>
<span class="sd">        Inner plume object for extracting variables from the state space.</span>
<span class="sd">    yo_local : `OuterPlume` object</span>
<span class="sd">        Outer plume object for extracting variables from the state space.</span>
<span class="sd">    particles : list of `dispersed_phases.PlumeParticle` objects</span>
<span class="sd">        List of `dispersed_phases.PlumeParticle` objects containing the</span>
<span class="sd">        dispersed phase local conditions and behavior.</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>
<span class="sd">    p : `ModelParams` object</span>
<span class="sd">        Object containing the fixed model parameters for the stratified</span>
<span class="sd">        plume model.</span>
<span class="sd">    fig : int</span>
<span class="sd">        Figure number.  Number of the figure window in which to draw the plot.</span>


<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">import</span> <span class="nn">matplotlib</span> <span class="k">as</span> <span class="nn">mpl</span>
    <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>

    <span class="c1"># Calculate some counting variables to set up memory for storing the</span>
    <span class="c1"># results before plotting</span>
    <span class="n">n_inner</span> <span class="o">=</span> <span class="n">zi</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">n_outer</span> <span class="o">=</span> <span class="n">zo</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">n_part</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">np</span>
    <span class="n">pchems</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_part</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">composition</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">pchems</span><span class="p">:</span>
            <span class="n">pchems</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">composition</span><span class="p">)</span>
    <span class="n">nchems</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">nchems</span>
    <span class="k">if</span> <span class="n">nchems</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">nchems</span> <span class="o">=</span> <span class="mi">1</span>

    <span class="c1"># Initialize space to store the inner plume solution</span>
    <span class="n">Qi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">Ji</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">Si</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">Hi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">Mpf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">,</span> <span class="n">pchems</span><span class="p">))</span>
    <span class="n">Hp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">))</span>
    <span class="n">Ci</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">nchems</span><span class="p">))</span>
    <span class="n">ui</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">bi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">si</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">Ti</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">ci</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">nchems</span><span class="p">))</span>
    <span class="n">rho_i</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">xi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">))</span>
    <span class="n">fb</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">))</span>
    <span class="n">Xi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">Fb</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">Ep</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>

    <span class="c1"># Initialize space to store the particle solution</span>
    <span class="n">Mp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">,</span> <span class="n">pchems</span><span class="p">))</span>
    <span class="n">Tp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">))</span>
    <span class="n">de</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">))</span>
    <span class="n">us</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">))</span>
    <span class="n">rho_p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">))</span>
    <span class="n">A</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">))</span>
    <span class="n">Cs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">,</span> <span class="n">pchems</span><span class="p">))</span>
    <span class="n">beta</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">,</span> <span class="n">pchems</span><span class="p">))</span>
    <span class="n">beta_T</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">n_part</span><span class="p">))</span>

    <span class="c1"># Get the ambient data on the same grid as the inner plume</span>
    <span class="n">Ta</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">Sa</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">P</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">rho_a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_inner</span><span class="p">)</span>
    <span class="n">ca</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_inner</span><span class="p">,</span> <span class="n">nchems</span><span class="p">))</span>

    <span class="c1"># Get the inner plume solution at each calculation level</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_inner</span><span class="p">):</span>
        <span class="n">yi_local</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">zi</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">yi</span><span class="p">[</span><span class="n">i</span><span class="p">,:],</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
        <span class="n">Qi</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">Q</span>
        <span class="n">Ji</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">J</span>
        <span class="n">Si</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">S</span>
        <span class="n">Hi</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">H</span>
        <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_part</span><span class="p">):</span>
            <span class="n">Mpf</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">yi_local</span><span class="o">.</span><span class="n">M_p</span><span class="p">[</span><span class="n">j</span><span class="p">])]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">M_p</span><span class="p">[</span><span class="n">j</span><span class="p">][:]</span>
            <span class="n">Mp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">m</span><span class="p">)]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">m</span><span class="p">[:]</span>
            <span class="n">Tp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">T</span>
            <span class="n">de</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">diameter</span><span class="p">(</span><span class="n">Mp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">m</span><span class="p">)],</span>
                                            <span class="n">Tp</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">],</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">P</span><span class="p">,</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">Sa</span><span class="p">,</span>
                                            <span class="n">yi_local</span><span class="o">.</span><span class="n">Ta</span><span class="p">)</span>
            <span class="n">us</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">us</span>
            <span class="n">rho_p</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">rho_p</span>
            <span class="n">A</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">A</span>
            <span class="n">Cs_local</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">Cs</span><span class="p">[:]</span>
            <span class="n">beta_local</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">beta</span><span class="p">[:]</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">Cs_local</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">Cs</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">Cs_local</span><span class="p">)]</span> <span class="o">=</span> <span class="n">Cs_local</span>
                <span class="n">beta</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">beta_local</span><span class="p">)]</span> <span class="o">=</span> <span class="n">beta_local</span>
            <span class="n">beta_T</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">.</span><span class="n">beta_T</span>
        <span class="n">Hp</span><span class="p">[</span><span class="n">i</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">H_p</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">yi_local</span><span class="o">.</span><span class="n">C</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">Ci</span><span class="p">[</span><span class="n">i</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">C</span><span class="p">[:]</span>
        <span class="n">ui</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">u</span>
        <span class="n">bi</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">b</span>
        <span class="n">si</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">s</span>
        <span class="n">Ti</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">T</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">yi_local</span><span class="o">.</span><span class="n">c</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">ci</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">c</span><span class="p">[:]</span>
        <span class="n">rho_i</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">rho</span>
        <span class="n">xi</span><span class="p">[</span><span class="n">i</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">xi</span><span class="p">[:]</span>
        <span class="n">fb</span><span class="p">[</span><span class="n">i</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">fb</span><span class="p">[:]</span>
        <span class="n">Xi</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">Xi</span>
        <span class="n">Fb</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">Fb</span>
        <span class="n">Ep</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">Ep</span>
        <span class="n">Ta</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">Ta</span>
        <span class="n">Sa</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">Sa</span>
        <span class="n">P</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">P</span>
        <span class="n">rho_a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">rho_a</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">yi_local</span><span class="o">.</span><span class="n">ca</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">ca</span><span class="p">[</span><span class="n">i</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">ca</span>

    <span class="c1"># Create an interpolator for the inner plume</span>
    <span class="n">neighbor</span> <span class="o">=</span> <span class="n">interp1d</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">zi</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">yi</span><span class="p">)</span><span class="o">.</span><span class="n">transpose</span><span class="p">())</span>

    <span class="c1"># Initialize space to store the outer plume solution</span>
    <span class="n">Qo</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_outer</span><span class="p">)</span>
    <span class="n">Jo</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_outer</span><span class="p">)</span>
    <span class="n">So</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_outer</span><span class="p">)</span>
    <span class="n">Ho</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_outer</span><span class="p">)</span>
    <span class="n">Co</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_outer</span><span class="p">,</span> <span class="n">nchems</span><span class="p">))</span>
    <span class="n">uo</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_outer</span><span class="p">)</span>
    <span class="n">bo</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_outer</span><span class="p">)</span>
    <span class="n">so</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_outer</span><span class="p">)</span>
    <span class="n">To</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_outer</span><span class="p">)</span>
    <span class="n">co</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_outer</span><span class="p">,</span> <span class="n">nchems</span><span class="p">))</span>
    <span class="n">rho_o</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_outer</span><span class="p">)</span>

    <span class="c1"># Get the inner plume solution at each calculation level</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_outer</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">yi_local</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">zo</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">neighbor</span><span class="p">(</span><span class="n">zo</span><span class="p">[</span><span class="n">i</span><span class="p">]),</span> <span class="n">particles</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
            <span class="n">yo_local</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">zo</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">yo</span><span class="p">[</span><span class="n">i</span><span class="p">,:],</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">yi_local</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="c1"># Above or below an inner plume segment; set bi = 0</span>
            <span class="n">yo_local</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">zo</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">yo</span><span class="p">[</span><span class="n">i</span><span class="p">,:],</span> <span class="n">profile</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="mf">0.</span><span class="p">)</span>
        <span class="n">Qo</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">Q</span>
        <span class="n">Jo</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">J</span>
        <span class="n">So</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">S</span>
        <span class="n">Ho</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">H</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">yo_local</span><span class="o">.</span><span class="n">C</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">Co</span><span class="p">[</span><span class="n">i</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">C</span><span class="p">[:]</span>
        <span class="n">uo</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">u</span>
        <span class="n">bo</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">b</span>
        <span class="n">so</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">s</span>
        <span class="n">To</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">T</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">yo_local</span><span class="o">.</span><span class="n">c</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">co</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">c</span><span class="p">[:]</span>
        <span class="n">rho_o</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">yo_local</span><span class="o">.</span><span class="n">rho</span>

    <span class="c1"># Figure -----------------------------------------------------------------</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>

    <span class="c1"># Volume flux</span>
    <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">221</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Qi</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Qo</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Q (m^3/s)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Momentum flux</span>
    <span class="n">ax2</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">222</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Ji</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="o">-</span><span class="n">Jo</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;J (m^4/s^2)&#39;</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Salinity flux</span>
    <span class="n">ax3</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">223</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Si</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">So</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;S (psu m^3/s)&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Heat flux</span>
    <span class="n">ax4</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">224</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Hi</span><span class="o">/</span><span class="mf">1.e6</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Ho</span><span class="o">/</span><span class="mf">1.e6</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;H (MJ/s)&#39;</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
    <span class="n">fig</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="c1"># Figure -----------------------------------------------------------------</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>

    <span class="c1"># Determine how many rows and columns of plots to make</span>
    <span class="n">nsp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">nchems</span><span class="p">))</span>
    <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">nchems</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">nsp</span><span class="p">:</span>
        <span class="n">nsp</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="c1"># Plot each dissolved flux separately</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nchems</span><span class="p">):</span>
        <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="n">nsp</span><span class="p">,</span> <span class="n">nsp</span><span class="p">,</span> <span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Ci</span><span class="p">[:,</span><span class="n">i</span><span class="p">],</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Co</span><span class="p">[:,</span><span class="n">i</span><span class="p">],</span> <span class="n">zo</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="n">yi_local</span><span class="o">.</span><span class="n">chem_names</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39; flux (kg/s)&#39;</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;inert&#39;</span> <span class="o">+</span> <span class="s1">&#39; flux (kg/s)&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">i</span><span class="o">/</span><span class="n">nsp</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">i</span><span class="o">/</span><span class="n">nsp</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
    <span class="n">fig</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="c1"># Figure -----------------------------------------------------------------</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_part</span><span class="p">):</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>

        <span class="c1"># Particle mass flux</span>
        <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">121</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Mpf</span><span class="p">[:,</span><span class="n">i</span><span class="p">,:],</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;M_pf (kg/s)&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Particle heat flux</span>
        <span class="n">ax2</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">122</span><span class="p">)</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Hp</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span><span class="o">/</span><span class="mf">1.e6</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Hf (MJ/s)&#39;</span><span class="p">)</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
        <span class="n">fig</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="c1"># Figure -----------------------------------------------------------------</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>

    <span class="c1"># Velocity</span>
    <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">221</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">ui</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">uo</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;u (m/s)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Half-width</span>
    <span class="n">ax2</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">222</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">bi</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">bo</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;b (m)&#39;</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">b_max</span> <span class="o">=</span> <span class="mf">1.25</span> <span class="o">*</span> <span class="p">(</span><span class="n">bo</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="p">(</span><span class="n">zo</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">zo</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="n">b_max</span><span class="p">])</span>

    <span class="c1"># Salinity</span>
    <span class="n">ax3</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">223</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">si</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">so</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Sa</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;s (psu)&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Temperature</span>
    <span class="n">ax4</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">224</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Ti</span> <span class="o">-</span> <span class="mf">273.15</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">To</span> <span class="o">-</span> <span class="mf">273.15</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Ta</span> <span class="o">-</span> <span class="mf">273.15</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;T (deg C)&#39;</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax4</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
    <span class="n">fig</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="c1"># Figure -----------------------------------------------------------------</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">ticklabel_format</span><span class="p">(</span><span class="n">useOffset</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>

    <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">rho_i</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">rho_o</span><span class="p">,</span> <span class="n">zo</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">rho_a</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;rho (kg/m^3)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
    <span class="n">fig</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="c1"># Figure -----------------------------------------------------------------</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>

    <span class="c1"># Determine how many rows and columns of plots to make</span>
    <span class="n">nsp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">nchems</span><span class="p">))</span>
    <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">nchems</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">nsp</span><span class="p">:</span>
        <span class="n">nsp</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="c1"># Plot each dissolved flux separately</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nchems</span><span class="p">):</span>
        <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="n">nsp</span><span class="p">,</span> <span class="n">nsp</span><span class="p">,</span> <span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">ticklabel_format</span><span class="p">(</span><span class="n">useOffset</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">ci</span><span class="p">[:,</span><span class="n">i</span><span class="p">],</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">co</span><span class="p">[:,</span><span class="n">i</span><span class="p">],</span> <span class="n">zo</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">ca</span><span class="p">[:,</span><span class="n">i</span><span class="p">],</span> <span class="n">zi</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="n">yi_local</span><span class="o">.</span><span class="n">chem_names</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39; concentration (kg/m^3)&#39;</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;inert&#39;</span> <span class="o">+</span> <span class="s1">&#39; concentration (kg/m^3)&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">i</span><span class="o">/</span><span class="n">nsp</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">i</span><span class="o">/</span><span class="n">nsp</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
    <span class="n">fig</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="c1"># Figure -----------------------------------------------------------------</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>

    <span class="c1"># Velocity</span>
    <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">221</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">xi</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Xi</span><span class="p">,</span> <span class="n">zi</span><span class="p">,</span> <span class="s1">&#39;k-&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;xi (--)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax1</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Half-width</span>
    <span class="n">ax2</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">222</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">fb</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Fb</span><span class="p">,</span> <span class="n">zi</span><span class="p">,</span> <span class="s1">&#39;k-&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;fb (kg/m^3)&#39;</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax2</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># Peeling flux</span>
    <span class="n">ax3</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">223</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Ep</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Ep (m^2/s)&#39;</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
    <span class="n">ax3</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

    <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
    <span class="n">fig</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="c1"># Figure -----------------------------------------------------------------</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_part</span><span class="p">):</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>

        <span class="c1"># Diameter</span>
        <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">331</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">de</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="mf">1000.</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;de (mm)&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax1</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Slip velocity</span>
        <span class="n">ax2</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">332</span><span class="p">)</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">us</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="mf">100.</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;us (cm)&#39;</span><span class="p">)</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax2</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Surface area</span>
        <span class="n">ax3</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">333</span><span class="p">)</span>
        <span class="n">ax3</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">A</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="mf">100.</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax3</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;A (cm^2)&#39;</span><span class="p">)</span>
        <span class="n">ax3</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax3</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax3</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Temperature</span>
        <span class="n">ax4</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">334</span><span class="p">)</span>
        <span class="n">ax4</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Tp</span><span class="p">[:,</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="mf">273.15</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax4</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Ti</span> <span class="o">-</span> <span class="mf">273.15</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax4</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Tp (deg C)&#39;</span><span class="p">)</span>
        <span class="n">ax4</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
        <span class="n">ax4</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax4</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax4</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Density</span>
        <span class="n">ax5</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">335</span><span class="p">)</span>
        <span class="n">ax5</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">rho_p</span><span class="p">[:,</span><span class="n">i</span><span class="p">],</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax5</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;rho_p (kg/m^3)&#39;</span><span class="p">)</span>
        <span class="n">ax5</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax5</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax5</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Beta_T</span>
        <span class="n">ax6</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">336</span><span class="p">)</span>
        <span class="n">ax6</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">beta_T</span><span class="p">[:,</span><span class="n">i</span><span class="p">],</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax6</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;beta_T (m/s)&#39;</span><span class="p">)</span>
        <span class="n">ax6</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax6</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax6</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Mp</span>
        <span class="n">ax7</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">337</span><span class="p">)</span>
        <span class="n">ax7</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Mp</span><span class="p">[:,</span><span class="n">i</span><span class="p">,:]</span><span class="o">/</span><span class="mf">1.e6</span><span class="p">,</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax7</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;mp (mg)&#39;</span><span class="p">)</span>
        <span class="n">ax7</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">&#39;Depth (m)&#39;</span><span class="p">)</span>
        <span class="n">ax7</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax7</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax7</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Cs</span>
        <span class="n">ax8</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">338</span><span class="p">)</span>
        <span class="n">ax8</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Cs</span><span class="p">[:,</span><span class="n">i</span><span class="p">,:],</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax8</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;Cs (kg/m^3)&#39;</span><span class="p">)</span>
        <span class="n">ax8</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax8</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax8</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="c1"># Beta</span>
        <span class="n">ax9</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">339</span><span class="p">)</span>
        <span class="n">ax9</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">beta</span><span class="p">[:,</span><span class="n">i</span><span class="p">,:],</span> <span class="n">zi</span><span class="p">)</span>
        <span class="n">ax9</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">&#39;beta (m/s)&#39;</span><span class="p">)</span>
        <span class="n">ax9</span><span class="o">.</span><span class="n">locator_params</span><span class="p">(</span><span class="n">tight</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">nbins</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
        <span class="n">ax9</span><span class="o">.</span><span class="n">invert_yaxis</span><span class="p">()</span>
        <span class="n">ax9</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>

        <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
        <span class="n">fig</span> <span class="o">+=</span> <span class="mi">1</span></div>

</pre></div>

          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../index.html">Texas A&M Oil spill / Outfall Calculator</a></h1>








<h3>Navigation</h3>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../user_manual.html">TAMOC User Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../unit_tests.html">Unit Tests</a></li>
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../bugs.html">Reporting Bugs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../readme.html">Read Me File</a></li>
<li class="toctree-l1"><a class="reference internal" href="../release.html">Release Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../license.html">License</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../index.html">Documentation overview</a><ul>
  <li><a href="index.html">Module code</a><ul>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2020, Scott A. Socolofsky.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 2.4.4</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
    </div>

    

    
  </body>
</html>